简体   繁体   English

Emacs-GDB有权中断而无需单步浏览所有文件

[英]Emacs - GDB trace right to interrupt without stepping through all files

I am working on Pintos OS project. 我正在研究Pintos OS项目。 I get this message: 我收到此消息:

Page fault at 0xbfffefe0: not present error writing page in user context.

The problem with Pintos OS project is that it won't simply tell the line and method that caused the exception. Pintos OS项目的问题在于,它不会简单地告诉导致异常的行和方法。

I know how to use breakpoints/watchpoints etc. but is there any way to step right to it without going through the WHOLE flow and ALL OS files line by line so that I could jump into line that caused exception and put breakpoint there? 我知道如何使用断点/监视点等,但是有没有办法直接通过它而无需逐行处理整个流程和所有OS文件,以便我可以跳入引起异常的行并将断点放在那里? I looked at GDB commands but didn't find anything. 我查看了GDB命令,但没有找到任何东西。

When I debug this project I have to step through the whole program until I find that error/exception which is very time consuming. 当我调试该项目时,我必须遍历整个程序,直到发现该错误/异常非常耗时。 There is probably a faster way to do this. 可能有一种更快的方法。

Thanks. 谢谢。 Whole trace: 整个痕迹:

nestilll@vdebian:~/Class/pintos/proj-3-bhling-nestilll-nsren/src/vm/build$ pintos -v -k -T 60 --qemu --gdb  --filesys-size=2 -p tests/vm/pt-grow-pusha -a pt-grow-pusha --swap-size=4 -- -q  -f run pt-grow-pusha
Use of literal control characters in variable names is deprecated at /home/nestilll/Class/pintos/src/utils/pintos line 909.
Prototype mismatch: sub main::SIGVTALRM () vs none at /home/nestilll/Class/pintos/src/utils/pintos line 933.
Constant subroutine SIGVTALRM redefined at /home/nestilll/Class/pintos/src/utils/pintos line 925.
warning: disabling timeout with --gdb
Copying tests/vm/pt-grow-pusha to scratch partition...
qemu -hda /tmp/N2JbACdqyV.dsk -m 4 -net none -nographic -s -S
PiLo hda1
Loading............
Kernel command line: -q -f extract run pt-grow-pusha
Pintos booting with 4,088 kB RAM...
382 pages available in kernel pool.
382 pages available in user pool.
Calibrating timer...  419,020,800 loops/s.
hda: 13,104 sectors (6 MB), model "QM00001", serial "QEMU HARDDISK"
hda1: 205 sectors (102 kB), Pintos OS kernel (20)
hda2: 4,096 sectors (2 MB), Pintos file system (21)
hda3: 98 sectors (49 kB), Pintos scratch (22)
hda4: 8,192 sectors (4 MB), Pintos swap (23)
filesys: using hda2
scratch: using hda3
swap: using hda4
Formatting file system...done.
Boot complete.
Extracting ustar archive from scratch device into file system...
Putting 'pt-grow-pusha' into the file system...
Erasing ustar archive...
Executing 'pt-grow-pusha':
(pt-grow-pusha) begin
Page fault at 0xbfffefe0: not present error writing page in user context.
pt-grow-pusha: dying due to interrupt 0x0e (#PF Page-Fault Exception).
Interrupt 0x0e (#PF Page-Fault Exception) at eip=0x804809c
 cr2=bfffefe0 error=00000006
 eax=bfffff8c ebx=00000000 ecx=0000000e edx=00000027
 esi=00000000 edi=00000000 esp=bffff000 ebp=bfffffa8
 cs=001b ds=0023 es=0023 ss=0023
pt-grow-pusha: exit(-1)
Execution of 'pt-grow-pusha' complete.
Timer: 71 ticks
Thread: 0 idle ticks, 63 kernel ticks, 8 user ticks
hda2 (filesys): 62 reads, 200 writes
hda3 (scratch): 97 reads, 2 writes
hda4 (swap): 0 reads, 0 writes
Console: 1359 characters output
Keyboard: 0 keys pressed
Exception: 1 page faults
Powering off...

to have the GDB debugger run and stop at the desired location: 使GDB调试器运行并在所需位置停止:

gdb filename <--start debug session br main <--set a breakpoint at the first line of the main() function r <--run until that breakpoint is reached br filename.c:linenumber <--set another breakpoint at the desired line of code c <--continue until second breakpoint is encuntered gdb filename <-启动调试会话br main <-在main()函数的第一行设置一个断点r <-运行直到达到该断点br filename.c:linenumber <-在所需的代码行c <-继续,直到出现第二个断点

The debugger will stop at the desired location in the file, IF it ever actually gets there, 如果调试器实际到达该位置,它将在文件中的所需位置停止,

When I debug this project I have to step through the whole program until I find what caused error/exception which is very time consuming. 当我调试该项目时,我必须遍历整个程序,直到找到导致错误/异常的原因,这是非常耗时的。 There is probably a faster way to do this. 可能有一种更快的方法。

Normally what you would do is set a breakpoint just before the error. 通常,您要做的就是在错误之前设置一个断点。 Then your program will run at full speed, without your intervention, until it reaches that point. 然后,您的程序将在没有干预的情况下全速运行,直到达到该点为止。

There are several wrinkles here. 这里有几条皱纹。

First, sometimes it is difficult to know where to put the breakpoint. 首先,有时很难知道将断点放在哪里。 In this case I suppose I would look for the code that is printing the message, then work backward from there. 在这种情况下,我想我将寻找正在打印消息的代码,然后从那里开始工作。 Sometimes you have to stop at the failure point, examine the stack, set a new breakpoint further up, and re-run the program. 有时,您必须在故障点停止,检查堆栈,进一步设置新的断点,然后重新运行程序。

Then there is the mechanics of setting the breakpoint. 然后是设置断点的机制。 One simple way is to break by function name, like break my_function . 一种简单的方法是按函数名称break my_function ,例如break my_function Another is to use the file name and line number, like break my_file.c:73 . 另一种方法是使用文件名和行号,例如break my_file.c:73

Finally, sometimes a breakpoint can be hit many times before the failure is seen. 最后,有时在遇到故障之前可以多次击中断点。 You can use ignore counts (see help ignore ) or conditional breakpoints (like break my_function if variable = 27 ) to limit the number of stops. 您可以使用忽略计数(请参阅help ignore )或条件断点(例如, break my_function if variable = 27 )来限制停止的次数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM