LinuxQuestions.org
Review your favorite Linux distribution.
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 04-22-2008, 10:17 AM   #1
HolyJoe
LQ Newbie
 
Registered: Feb 2008
Distribution: Ubuntu
Posts: 20

Rep: Reputation: 0
How to use gdb to trace the glibc functions and linux system calls?


Hi,

How to use gdb to trace the glibc functions and linux system calls ?
For example, I want to trace into printf c library routine and _exit system call,
Does it need install some source package?
 
Old 04-22-2008, 02:15 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 76
You need to get a build of glibc with debugging symbols included.
 
Old 04-23-2008, 09:04 AM   #3
HolyJoe
LQ Newbie
 
Registered: Feb 2008
Distribution: Ubuntu
Posts: 20

Original Poster
Rep: Reputation: 0
How to get a build of glibc?

Quote:
Originally Posted by osor View Post
You need to get a build of glibc with debugging symbols included.
Thank you for your help.

But, How to get a build of glibc?
and How to trace the system call?
 
Old 04-23-2008, 10:25 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 76
Quote:
Originally Posted by HolyJoe View Post
But, How to get a build of glibc?
You should be able to get it from your distro’s package manager or binary repositories (in order for me to be more specific, you will need to tell what distro you use).
Quote:
Originally Posted by HolyJoe View Post
How to trace the system call?
Set a breakpoint and step through like any other function. If all you need is the arguments of the function, the normal glibc should work fine (as long as your program itself is compiled with debugging symbols).

This should all be in a basic primer on gdb.
 
Old 04-24-2008, 09:06 AM   #5
HolyJoe
LQ Newbie
 
Registered: Feb 2008
Distribution: Ubuntu
Posts: 20

Original Poster
Rep: Reputation: 0
I'll try your instruction.

Quote:
Originally Posted by osor View Post
You should be able to get it from your distro’s package manager or binary repositories (in order for me to be more specific, you will need to tell what distro you use).

Set a breakpoint and step through like any other function. If all you need is the arguments of the function, the normal glibc should work fine (as long as your program itself is compiled with debugging symbols).

This should all be in a basic primer on gdb.
Thank you for your warm help.
 
Old 12-27-2009, 05:28 PM   #6
spyro
LQ Newbie
 
Registered: Dec 2009
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by HolyJoe View Post
Thank you for your warm help.
In case anyone else is reading, remember that some syscalls have no extra fat and effecively compile into a software interrupt (SWI on ARM or INT0x80 on x86) so you will find gdb refuses to step into them (it cant).
 
Old 12-27-2009, 07:44 PM   #7
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
you may also find the combination of strace and ltrace helpful, if you are just looking to observe syscalls without necessarily being able to debug them.
 
Old 12-29-2009, 06:26 PM   #8
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 76
Quote:
Originally Posted by spyro View Post
In case anyone else is reading, remember that some syscalls have no extra fat and effecively compile into a software interrupt (SWI on ARM or INT0x80 on x86) so you will find gdb refuses to step into them (it cant).
Yes. The “true” system calls (those documented in section 2 of the manpages) are eventually unable to be debugged in userspace. These will have at least a minimal amount of wrapping (for e.g., errno assignment) which is visible in a debugging libc.
 
Old 12-29-2009, 06:58 PM   #9
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
purportedly, gdb 7.0 can trap syscalls by index:

(gdb) catch syscall 60
Catchpoint 3 (syscall 'exit' [60])


I have not tried it myself, but it is documented in the release notes.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how does java calls the system calls which are written in c babu198649 Linux - General 3 12-05-2011 04:40 AM
gdb in glibc functions Harald Rudell Programming 0 09-05-2007 03:45 PM
System calls/functions to execute a file within a program psandeepnair1985 Programming 1 05-02-2007 03:37 AM
How to interpret Stack trace from gdb out put NeoMagic Linux - Desktop 1 12-29-2006 12:52 AM
lisp/scheme: is there a way to trace all functions? psiakr3w Programming 3 08-09-2004 08:46 AM

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

All times are GMT -5. The time now is 06:00 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration