LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-27-2010, 05:05 PM   #1
jason_m
Member
 
Registered: Jun 2009
Posts: 33

Rep: Reputation: 12
gdb, fork(), exec()


I'm looking for a little help on using gdb to debug a program. The program is very similar to the one here.

The program creates a child process with fork(), which then executes a new file using execve(). The file that execve() loads up is compiled hand-written assembly compiled with "as -g".

I can get gdb to step into the child process after the call to fork() by issuing the command "set follow-fork-mode child". I've played with "set follow-exec-mode new", but that doesn't seem to be impacting what happens after I step past/into the execve() call.

The basic layout of what I am doing in gdb is as follows:
Code:
$ gdb parent_program

(gdb) break main
(gdb) run
(gdb) break assembly_program.s:9
No source file named assembly_program.s.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (assembly_program.s:9) pending.
(gdb) set follow-fork-mode child
(gdb) set follow-exec-mode new
stepping into the execve() line
Code:
(gdb) s
process 6629 is executing new program: /home/jason/Development/asm/assembly_program

Program exited normally.
I read that re-issuing the "run" command might restart the program loaded by execve(), so issuing "run":
Code:
(gdb) run
Starting program: /home/jason/Development/asm/assembly_program

Program received signal SIGSEGV, Segmentation fault.
_start () at assembly_program.s:19
(gdb)
I have also tried setting the break point after the first program completes and prior to re-issuing the run command:
Code:
[New process 6638]
process 6638 is executing new program: /home/jason/Development/asm/assembly_program

Program exited normally.
(gdb) break assembly_program.s:9
Note: breakpoint -11 also set at pc 0x4000b0.
Breakpoint 2 at 0x4000b0: file assembly_program.s, line 9.
(gdb) run
Starting program: /home/jason/Development/asm/assembly_program

Program received signal SIGSEGV, Segmentation fault.
_start () at assembly_program.s:19
(gdb)
But either way, gdb blows right past my breakpoint. Any thoughts on how to debug this program?
 
Old 08-28-2010, 11:03 AM   #2
vose
Member
 
Registered: Aug 2002
Location: tennessee
Distribution: gentoo
Posts: 39

Rep: Reputation: 15
I have no idea whether this would help, but...

I would try to change my assembly code so that the first thing it does is (something like) go into an infinite loop (perhaps you want something nice in the loop, like sleep or yield) -- such that the loop would terminate if the value of a variable in main memory were different from what it was.

Next run the code, which eventually forks, etc., and eventually executes your modified assembly code and gets stuck in the infinite loop.

Fire up ddd and attach to the process that corresponds to the executing assembly (which is stuck in the infinite loop). Set a breakpoint after the loop. Set the value of the variable in main memory such that the loop will be exited. Continue (in ddd) and perhaps then -- fingers crossed -- your breakpoint will be encountered and not ignored.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux C exec fork karana Linux - Newbie 1 03-21-2009 07:48 AM
fork() exec() or system() kalleanka Programming 4 09-18-2007 04:16 AM
Fork exec problem bhupeshchawda Programming 3 04-19-2007 04:58 AM
how to fork/ exec schneidz Programming 10 08-30-2005 11:50 AM
Fork 'n Exec sourceman Linux - General 4 02-14-2002 02:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration