-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from epasveer/PLAY-3d-array-visualizer
Play 3d array visualizer
- Loading branch information
Showing
8 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
helloarrayofstructs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.PHONY: all | ||
all: helloarrayofstructs | ||
|
||
helloarrayofstructs: helloarrayofstructs.cpp | ||
g++ -g -o helloarrayofstructs helloarrayofstructs.cpp | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f helloarrayofstructs helloarrayofstructs.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
From this discussion about displaying arrays of structs (maybe a struct that has a 3d array?). | ||
|
||
https://github.com/epasveer/seer/discussions/243 | ||
|
||
May need to improve the 2D visualizer into a 3D visualizer. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <stdlib.h> | ||
#include <iostream> | ||
|
||
struct CoordsData { | ||
int x; | ||
int y; | ||
int z; | ||
}; | ||
|
||
struct CoordsArray { | ||
struct CoordsData* data; | ||
int num; | ||
}; | ||
|
||
int main(void) { | ||
|
||
struct CoordsArray arr; | ||
arr.num = 10; | ||
arr.data = (CoordsData*)malloc(sizeof(struct CoordsData) * arr.num); | ||
|
||
for (int i = 0; i < arr.num; ++i) { | ||
arr.data[i].x = i; | ||
arr.data[i].y = i + i; | ||
arr.data[i].z = i * i; | ||
|
||
std::cout << i << ") x=" << arr.data[i].x << " y=" << arr.data[i].y << " z=" << arr.data[i].z << std::endl; | ||
} | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
helloforksegv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.PHONY: all | ||
all: helloforksegv | ||
|
||
helloforksegv: helloforksegv.cpp | ||
g++ -g -o helloforksegv helloforksegv.cpp | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f helloforksegv helloforksegv.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
From a discussion here. Can Seer stop at the right process (after a fork) when a SEGV happens. | ||
|
||
https://www.reddit.com/r/C_Programming/comments/1f1ahcp/is_there_a_way_to_debug_a_multiprocess_program/ | ||
|
||
Some resources. | ||
|
||
https://moss.cs.iit.edu/cs351/gdb-inferiors.html | ||
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Inferiors-Connections-and-Programs.html#Inferiors-Connections-and-Programs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include<stdio.h> | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
|
||
int main() { | ||
pid_t pid1 = fork(); | ||
|
||
if (pid1 < 0) { | ||
// Error occurred while forking | ||
perror("Fork failed"); | ||
return 1; | ||
} else if (pid1 == 0) { | ||
// First child process | ||
printf("First child process is running\n"); | ||
|
||
sleep(200000); | ||
|
||
printf("First child process completed\n"); | ||
return 0; | ||
} else { | ||
// Parent process | ||
printf("Parent process is running\n"); | ||
|
||
pid_t pid2 = fork(); | ||
|
||
if (pid2 < 0) { | ||
// Error occurred while forking | ||
perror("Fork failed"); | ||
return 1; | ||
} else if (pid2 == 0) { | ||
// Second child process | ||
printf("Second child process is running\n"); | ||
|
||
// Simulate a crash by accessing an invalid memory address | ||
int *ptr = NULL; | ||
*ptr = 10; | ||
|
||
printf("This line will not be executed\n"); | ||
return 0; | ||
} else { | ||
// Parent process | ||
|
||
int status2; | ||
waitpid(pid2, &status2, 0); | ||
|
||
if (WIFEXITED(status2)) { | ||
printf("Second child process exited with status: %d\n", WEXITSTATUS(status2)); | ||
} else if (WIFSIGNALED(status2)) { | ||
printf("Second child process terminated by signal: %d\n", WTERMSIG(status2)); | ||
} | ||
|
||
// Wait for the first child process to finish | ||
int status1; | ||
waitpid(pid1, &status1, 0); | ||
|
||
if (WIFEXITED(status1)) { | ||
printf("First child process exited with status: %d\n", WEXITSTATUS(status1)); | ||
} else if (WIFSIGNALED(status1)) { | ||
printf("First child process terminated by signal: %d\n", WTERMSIG(status1)); | ||
} | ||
|
||
|
||
sleep(500000); | ||
} | ||
} | ||
|
||
return 0; | ||
} |