-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Provide gdb helper script to ease debugging #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I would like to defer to @afcidk . |
|
Instead of providing conditional builds, how about consolidating them by extra runtime option |
|
Sounds great. I am going to read this article later.
In my experience, optimizations that do interfere with debugging without -Og. |
|
Any change for further work? |
|
Sorry for the delay. |
You can force push revised commits. |
f72d3c7 to
5008d53
Compare
qtest.c
Outdated
| "pointer"); | ||
| char cmd[1024] = {0}; | ||
| snprintf(cmd, sizeof(cmd), "gdb -q -p %d -ex bt", getpid()); | ||
| if (system(cmd) != 0) { |
There was a problem hiding this comment.
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).
5008d53 to
5a52173
Compare
|
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
To sum up, create a script which contain two features:
About core-dump file, do we need to change /proc/sys/kernel/core_pattern? Because it needs permission. |
|
As for |
5a52173 to
454b7fb
Compare
|
Please rebase the latest |
454b7fb to
040adbb
Compare
|
Oh, I forget to rebase the local branch. |
a1e6a1d to
83122a6
Compare
|
You shall update documentation in top-level |
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` |
There was a problem hiding this comment.
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
qtestwithoutSIGALRMand/or analyzes generated core dump file.
There was a problem hiding this comment.
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.
|
File |
5be9ead to
599aef8
Compare
README.md
Outdated
| ``` | ||
| * Enter GDB without interruption by **SIGALRM** | ||
| ``` | ||
| $ ./debug --d |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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.
b60ae64 to
779de97
Compare
README.md
Outdated
|
|
||
| This script provides two options for debugging. | ||
| ``` | ||
| $ ./debug.py -h |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
779de97 to
99ede05
Compare
README.md
Outdated
| Starting program: lab0-c/qtest | ||
| cmd> | ||
| ``` | ||
| * It's handy to analyze the core dump file. |
There was a problem hiding this comment.
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.
99ede05 to
8aec1a2
Compare
README.md
Outdated
|
|
||
| ## Debugging Facilities | ||
|
|
||
| This script provides two options for debugging. |
There was a problem hiding this comment.
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.
8aec1a2 to
76f1a5c
Compare
Add "Debugging Facilities" section to README.md
76f1a5c to
440969f
Compare
|
Thank @wilson6405 for contributing! |
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