[lldb-dev] Question for debugging a forked program and reload symbol
jingham at apple.com
jingham at apple.com
Tue Nov 19 15:41:37 PST 2013
On Nov 19, 2013, at 2:49 PM, Yin Ma <yin at affinic.com> wrote:
> Hi
>
> I have a very simple program
>
> #include <stdio.h>
> int num = 0;
> int main(int argc, char*argv[]){
> int pid;
> int num;
> pid = fork();
> printf("%d", pid);
> if(pid == 0){ /*child*/
> num = 1;
> }else if(pid > 0){ /*parent*/
> num = 2;
> }
> printf("%d", num);
> while(num) {
> num ++;
> }
>
> return num;
> }
>
> I break at num = 1;
> B g.c:9
>
> And I run
> The program never hits the breakpoint.
> And the output from the program is
> 4862
> 2
> 0
>
> However, if I run in terminal
> The output is
> 4813
> 2
> 0
> 1
>
> It looks like the forked portion is not available in lldb.
> What’s going on here?
Since fork copies the address space of the parent, the breakpoint trap we put in goes along for the ride, and when the child gets running it hits it. lldb doesn't follow forks at present, so it doesn't know to catch the child's breakpoint hit, and so the child will just die. That's why you didn't see its output.
>
> Another question:
> If I am debugging an executable, after I modified the source
> And re-compile the executable, the next time when I run
> Under debugger, gdb will show reload symbol. I didn’t see
> The same thing for lldb or any output about updating. Do
> I have to reload the executable every time I modify it?
lldb just reloads the executable if it changes. We don't print a message saying we did this. Maybe we ought to, just to reassure folks we did the right thing?
>
> I am using Moutain Lion, lldb-179.5
That's a pretty old lldb, but I'm pretty sure we've done this correctly for quite some time.
Jim
More information about the lldb-dev
mailing list