Skip to content

Conversation

@wilson6405
Copy link

When qtest stopped by debugger during the tracing, it would over
time_limit seconds and trigger timeout exception.

Signed-off-by: Kickasson face.ateam0902@gmail.com

@jserv
Copy link
Contributor

jserv commented Jan 31, 2020

I would like to defer to @afcidk .

@jserv
Copy link
Contributor

jserv commented Feb 1, 2020

Instead of providing conditional builds, how about consolidating them by extra runtime option --debug which would suppress exception handling?
Reference: https://www.mono-project.com/docs/debug+profile/debug/

@wilson6405
Copy link
Author

Sounds great. I am going to read this article later.
Under the suppressing exception handling I have two ideas:

  1. Active: trigger gdb shell and attach qtest which is received signal SIGSEGV
  2. Passive: use extra run-time option -d during gdb debugging

In my experience, optimizations that do interfere with debugging without -Og.

@jserv
Copy link
Contributor

jserv commented Feb 7, 2020

Any change for further work?

@wilson6405
Copy link
Author

Sorry for the delay.
Should I update this PR or create a new one?

@jserv
Copy link
Contributor

jserv commented Feb 8, 2020

Sorry for the delay.
Should I update this PR or create a new one?

You can force push revised commits.

qtest.c Outdated
"pointer");
char cmd[1024] = {0};
snprintf(cmd, sizeof(cmd), "gdb -q -p %d -ex bt", getpid());
if (system(cmd) != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use system(), which might lead to unexpected execution flow. Instead, use posix_spawn(3) for fine-grained control over external process(es).

@wilson6405
Copy link
Author

Should I replace -O1 with -Og?

@jserv
Copy link
Contributor

jserv commented Feb 10, 2020

Should I replace -O1 with -Og?

I expect such build-specific changes should take place in another pull request.

qtest.c Outdated
char cmd[64] = {0};
snprintf(cmd, sizeof(cmd), "gdb -q -p %d -ex bt", getpid());
char *argv[] = {"sh", "-c", cmd, NULL};
if ((ret = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ)) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@afcidk, Please take a look over the implementation. I am not sure if we shall raise signals when it takes much longer time to launch GDB than usual.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid launching GDB within qtest. Instead, we can prepare specific GDB scripts which deal with certain signals and/or process flow.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with that. We could use handle SIGALRM ignore to deal with SIGALRM or other signals.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could provide an option to enable qtest to crash manually by adding functions such as abort() in sigsegvhandler to generate the core file for further analysis.

@wilson6405
Copy link
Author

To sum up, create a script which contain two features:

  1. Setup handle SIGALRM ignore first and run qtest in gdb shell.
  2. Analyze core-dump file

About core-dump file, do we need to change /proc/sys/kernel/core_pattern? Because it needs permission.

@jserv
Copy link
Contributor

jserv commented Feb 20, 2020

As for /proc/sys/kernel/core_pattern, you can detect and assist users to configure kernel via sysctl or procfs accordingly.

@jserv
Copy link
Contributor

jserv commented Feb 21, 2020

Please rebase the latest master branch

@wilson6405
Copy link
Author

Oh, I forget to rebase the local branch.

@wilson6405 wilson6405 force-pushed the pull-request branch 2 times, most recently from a1e6a1d to 83122a6 Compare February 21, 2020 14:58
@jserv
Copy link
Contributor

jserv commented Feb 21, 2020

You shall update documentation in top-level README.md.

@jserv jserv requested a review from afcidk February 21, 2020 15:45
README.md Outdated
* Makefile : Builds the evaluation program `qtest`
* README.md : This file
* scripts/driver.py : The driver program, runs `qtest` on a standard set of traces
* scripts/debug.py : The debug program, debug `qtest` without interruption by **SIGALRM** or analyze core-dump which is generated by `qtest`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the description to

The helper program for GDB, executes qtest without SIGALRM and/or analyzes generated core dump file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Append a new section about debugging facilities.

@jserv
Copy link
Contributor

jserv commented Feb 22, 2020

File .gitignore should be updated to include core.

@wilson6405 wilson6405 force-pushed the pull-request branch 2 times, most recently from 5be9ead to 599aef8 Compare February 23, 2020 07:13
README.md Outdated
```
* Enter GDB without interruption by **SIGALRM**
```
$ ./debug --d
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was debug located here?

README.md Outdated
* XX is the trace number (1-15). CAT describes the general nature of the test.
* traces/trace-eg.cmd : A simple, documented trace file to demonstrate the operation of `qtest`

## Usage of debug.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the section name to "Debugging Facilities"

README.md Outdated
This script provides two options for dedugging
```
-d, --debug Enter gdb shell
-a, --analyze Analyze the core-dump file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually say "core dump file" or "core dump" without dashes.

scripts/debug.py Outdated
@@ -0,0 +1,83 @@
#!/usr/bin/python3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change it to #!/usr/bin/env python3.

@wilson6405 wilson6405 force-pushed the pull-request branch 2 times, most recently from b60ae64 to 779de97 Compare February 23, 2020 12:19
README.md Outdated

This script provides two options for debugging.
```
$ ./debug.py -h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be $ scripts/debug.py

README.md Outdated
* Makefile : Builds the evaluation program `qtest`
* README.md : This file
* scripts/driver.py : The driver program, runs `qtest` on a standard set of traces
* scripts/debug.py : The helper program for GDB, executes qtest without SIGALRM and/or analyzes generated core dump file. For more detial: [Debugging Facilities](#Debugging-Facilities)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to mention its detailed usage since this section is a listing for files.

README.md Outdated
The core dump file was created in the working directory of the `qtest`.
* Allow the core dumps by using shell built-in command **ulimit**.
```
$ ulimit -c unlimited // Set core file size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't mix C++-style comments within shell commands.

1. Setup handle SIGALRM ignore first and run qtest in gdb shell
2. Analyze core dump file
README.md Outdated
Starting program: lab0-c/qtest
cmd>
```
* It's handy to analyze the core dump file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shall emphasize on the features and motivations regarding analysis on core dump as well.

README.md Outdated

## Debugging Facilities

This script provides two options for debugging.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, summarize the motivations of the GDB helper program in this section.

Add "Debugging Facilities" section to README.md
@jserv jserv changed the title Avoid throwing exception during gdb debugging Provide gdb helper script to ease debugging Feb 25, 2020
@jserv jserv merged commit 4430c35 into sysprog21:master Feb 25, 2020
@jserv
Copy link
Contributor

jserv commented Feb 25, 2020

Thank @wilson6405 for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants