• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to get source name/line number of backtrace?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to get source name/line number of backtrace?


  • Subject: How to get source name/line number of backtrace?
  • From: Samuel DELMONT <email@hidden>
  • Date: Wed, 4 Nov 2009 10:14:23 +0100

Hi,

I am using backtrace, dladdr and demangle to print the call stack of my program like that :

void* callstack[128];
int frames = backtrace(callstack, 128);
for(int i=0;i<frames;++i)
{
Dl_info info;
int res = dladdr(callstack[i], &info);
if(res!=0)
{
size_t length=0;
int status=0;
char* name = __cxxabiv1::__cxa_demangle(info.dli_sname,NULL,&length,&status);
printf (" : %s + %d %s\n", (0 == status) ? name : info.dli_sname, (unsigned int)((unsigned int)callstack[i] - (unsigned int)info.dli_saddr), info.dli_fname);
}
}

I get the name of the function and its arguments but I would like to have the source file's name and the line number of each address of the stack. I know that gdb can do this with "info line *addr", but I want to do it programmatically.

Is there a way to get the source name/line number from backtrace or is it possible to call gdb commands programmatically?

Thanks for any help,

Sam
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to get source name/line number of backtrace?
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Using projects & targets efficiently
  • Next by Date: Re: Version Control [was: Damaging the source code]
  • Previous by thread: Re: Using projects & targets efficiently
  • Next by thread: Re: How to get source name/line number of backtrace?
  • Index(es):
    • Date
    • Thread