Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [apple scitech] leopard gdb problem



Nope. I tried breaking on exit and _exit, and gdb didn't stop their either. I do have a ton of classes some of which are global, so something could be going on there. I'll have to dig into things. I should try and learn exactly how C++ starts up things.

Thanks for ideas.

Dave

On Nov 27, 2007, at 6:21 PM, Rich Cook wrote:

Good point, it's possible to exit before main is called!
I suggest you put a breakpoint in the exit function or in _exit_ or whatever it's called (see your C manual for what this is called, I'm lazy! :-)


On Nov 27, 2007, at 3:16 PM, Jonathan Bringhurst wrote:

After some further consideration, I went out of my way to figure out I
could get exactly the output you're getting. This doesn't use ptrace,
but it's not something you would likely do on accident. I figured I'd
post this because there might be a (very, very, very) slight chance
that you're doing something similar with a global class. Here's the
gdb transcript where you see different output for normal shell
execution and within gdb...


haven:test jon$ g++ -o test test.cc
haven:test jon$ ./test
shouldn't get here
haven:test jon$ gdb test
GNU gdb 6.3.50-20050815 (Apple version gdb-768) (Tue Oct 2 04:07:49 UTC 2007)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin"...Reading symbols for
shared libraries .... done


(gdb) break main
Breakpoint 1 at 0x1e42
(gdb) r
Starting program: /Users/jon/test/test
Reading symbols for shared libraries +++. done
darwin-i386

Program exited normally.
(gdb)

And here's the code....

#include <sys/types.h>
#include <sys/ptrace.h>
#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/sysctl.h>

// stolen from the ADC website
static bool AmIBeingDebugged(void)
// Returns true if the current process is being debugged (either
// running under the debugger or has a debugger attached post facto).
{
int junk;
int mib[4];
struct kinfo_proc info;
size_t size;


   // Initialize the flags so that, if sysctl fails for some bizarre
   // reason, we get a predictable result.

   info.kp_proc.p_flag = 0;

// Initialize mib, which tells sysctl the info we want, in this case
// we're looking for information about a specific process ID.
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();


// Call sysctl.
size = sizeof(info);
junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
assert(junk == 0);


   // We're being debugged if the P_TRACED flag is set.
   return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
}

// code to run before the main()
class premain {
public:
 premain(void);
};

premain::premain(void) {
 if(AmIBeingDebugged()) {
   printf("darwin-i386\n");
   exit(EXIT_SUCCESS);
 }
}

// instance in global scope
premain *mypremain = new premain();

int main(void){
 printf("shouldn't get here\n");
 return 0;
}

I hope that helps. This seems like it might be an interesting problem
if it's something to do with your actual code and not something to do
with how gdb is configured.

-Jon Bringhurst <email@hidden>

On Nov 27, 2007 5:19 PM, Jonathan Bringhurst <email@hidden> wrote:
Seems to work fine for me on leopard.

haven:test jon$ uname -a
Darwin haven 9.1.0 Darwin Kernel Version 9.1.0: Wed Oct 31 17:46:22
PDT 2007; root:xnu-1228.0.2~1/RELEASE_I386 i386
haven:test jon$ cat test.c
#include <stdio.h>
main(){printf("hw\n");}
haven:test jon$ cc -o test test.c
haven:test jon$ gdb test
...snip...
(gdb) break main
Breakpoint 1 at 0x1fde
(gdb) r
Starting program: /Users/jon/test/test
Reading symbols for shared libraries ++. done
Breakpoint 1, 0x00001fde in main ()
(gdb) c
Continuing.
hw
Program exited with code 012.
(gdb)

Perhaps you have ptrace() called with PT_DENY_ATTACH? This could
simulate the behavior you're currently experiencing.

-Jon Bringhurst <email@hidden>


On Nov 27, 2007 4:40 PM, Dave Chen <email@hidden> wrote:




When I try to run my command-line programs in gdb all it does is print
"darwin-i386" and then exit normally. It never actually runs the program.


Here's an example:


puget => gdb fillHoles
GNU gdb 6.3.50-20050815 (Apple version gdb-768) (Tue Oct 2 04:07:49 UTC
2007)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin"...Reading symbols for shared
libraries ....... done


(gdb) b main
Breakpoint 1 at 0x100004b5f: file
/nfs/mead/Users/dave/dsrc/geom/fillHoles.C, line 527.
(gdb) r
darwin-i386

Program exited normally.


It never even stops at the breakpoint I put at main.

Anyone have any idea what is going on or seen anything similar? If I run
the program without gdb, I can attach to the process OK, but I just can't
start programs in gdb.


Thanks,
Dave


David T. Chen, PhD [Lockheed Martin contractor]
mailto:email@hidden http://erie.nlm.nih.gov/~dave
phone:301.435.3264 iphone:301.524.3174
Office of High Performance Computing and Communications
National Library of Medicine


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Scitech mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/scitech/email@hidden

This email sent to email@hidden


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Scitech mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/scitech/email@hidden

This email sent to email@hidden

--
✐Richard Cook
✇ Lawrence Livermore National Security
Bldg-453 Rm-4037, Mail Stop L-557
7000 East Avenue, Livermore, CA, 94550, USA
☎ (office) (925) 423-9605
☎ (fax) (925) 423-6961
---
Information Management & Graphics Grp., Services & Development Div., Integrated Computing & Communications Dept.
(opinions expressed herein are mine and not those of LLNS)



_______________________________________________ Do not post admin requests to the list. They will be ignored. Scitech mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/scitech/email@hidden

This email sent to email@hidden
References: 
 >[apple scitech] leopard gdb problem (From: Dave Chen <email@hidden>)
 >Re: [apple scitech] leopard gdb problem (From: "Jonathan Bringhurst" <email@hidden>)
 >Re: [apple scitech] leopard gdb problem (From: "Jonathan Bringhurst" <email@hidden>)
 >Re: [apple scitech] leopard gdb problem (From: Rich Cook <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.