SIGSEGV when run a program in gdb
- Dominant language
- JavaScript
- Stars
- 23.5k
- Forks
- 1.9k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 7
Description
I want to debug my program with gdb on v86. But after just loaded my program to gdb and started, I got "Program received signal SIGSEGV, Segmentation fault".
And I tried to toggle breakpoint, the program could be paused and continue at first few breakpoints, but I still got "Program received signal SIGSEGV, Segmentation fault" if I continue later.
The program I loaded can be run correctly without gdb. Is there any unimplemented feature or bug in vm? Or any option missing while building image?
I'm working on debugging v86 in my browser to find it, but it seems not easy. Glad to contribute if it is caused by something unimplemented or bug.
Steps here:
1. Start gdb with target program loaded
I use yasm for demonstration.
```
cd /usr/bin
gdb ./yasm
```
2. Toggle breakpoint at 0x0 and run to pause program at first instruction.
```
(gdb) b *0
Breakpoint 1 at 0x0
(gdb) r
Starting program: /usr/bin/yasm
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x0
(gdb) disas
Dump of assembler code for function _start:
=> 0xb7f53237 <+0>: call 0xb7f52f50 <_dl_start>
0xb7f5323c <+5>: mov %eax,%edi
0xb7f5323e <+7>: call 0xb7f53243 <_start+12>
0xb7f53243 <+12>: pop %ebx
0xb7f53244 <+13>: add $0x2db1,%ebx
0xb7f5324a <+19>: mov 0x48(%ebx),%eax
```
3. Delete breakpoint above and toggle new breakpoints.
The first instruction in _start is a call to _dl_start, so I toggle breakpoints at first two instructions of _dl_start.
```
(gdb) i b
Num Type Disp Enb Address What
1 breakpoint keep y 0x00000000
(gdb) delete 1
(gdb) b *(_dl_start)
Breakpoint 2 at 0xb7fb6f50
(gdb) b *(_dl_start+1)
Breakpoint 3 at 0xb7fb6f51
(gdb) i b
Num Type Disp Enb Address What
2 breakpoint keep y 0xb7fb6f50 <_dl_start>
3 breakpoint keep y 0xb7fb6f51 <_dl_start+1>
```
4. Continue
The program can be paused at breakpoint 2 (_dl_start + 0) like this.
```
(gdb) c
Continuing.
Breakpoint 2, 0xb7f8af50 in _dl_start () from /lib/ld-uClibc.so.0
(gdb) disas
Dump of assembler code for function _dl_start:
=> 0xb7f8af50 <+0>: push %ebp
0xb7f8af51 <+1>: mov %esp,%ebp
0xb7f8af53 <+3>: push %edi
0xb7f8af54 <+4>: push %esi
0xb7f8af55 <+5>: push %ebx
0xb7f8af56 <+6>: sub $0x1bc,%esp
0xb7f8af5c <+12>: call 0xb7f8b26b <__x86.get_pc_thunk.bx>
```
And there is a break point at (_dl_start + 1), it is expected to be paused at breakpoint 3 (_dl_start + 1) if I continue again.
5. Continue again.
It says SIGSEGV like this.
```
(gdb) c
Continuing.
Program received signal SIGSEGV, Segmentation fault.
0x42f8b26b in ?? ()
(gdb) i s
#0 0x42f8b26b in ?? ()
#1 0x08049c95 in ?? ()
#2 0xb7f8b23c in _start () from /lib/ld-uClibc.so.0
```
Image here:
`https://pan.baidu.com/s/1Udjtb9_SAkIIW9zg09jHsw`
Password: heuf
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.