Skip to content

Commit

Permalink
Merge pull request #244 from epasveer/PLAY-3d-array-visualizer
Browse files Browse the repository at this point in the history
Play 3d array visualizer
  • Loading branch information
epasveer authored Aug 30, 2024
2 parents adb7922 + dcd5a6a commit 1ab6cd5
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/helloarrayofstructs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
helloarrayofstructs
10 changes: 10 additions & 0 deletions tests/helloarrayofstructs/Makefile
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

7 changes: 7 additions & 0 deletions tests/helloarrayofstructs/README
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.

31 changes: 31 additions & 0 deletions tests/helloarrayofstructs/helloarrayofstructs.cpp
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;
}

1 change: 1 addition & 0 deletions tests/helloforksegv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
helloforksegv
10 changes: 10 additions & 0 deletions tests/helloforksegv/Makefile
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

9 changes: 9 additions & 0 deletions tests/helloforksegv/README
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

69 changes: 69 additions & 0 deletions tests/helloforksegv/helloforksegv.cpp
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;
}

0 comments on commit 1ab6cd5

Please sign in to comment.