Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Attaching strace to a gdb'd program

  • 24-06-2004 11:08am
    #1
    Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭


    Hey guys,
    I'm trying to step through a simple program with gdb, and I'd like to attach strace to the program being debugged so that I can see what system calls are being performed by each individual line as I step through it. However it's not letting me...

    I run 'gdb ./program' and set a breakpoint, then enter a 'run' command. The program gets started as a process which gdb then attaches itself to (as far as I understand it, I could be wrong), and so I find out the process number with a 'ps'. I then run 'strace -p 1234' or whatever the pid is, whereupon it gives me

    attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted

    Can you only attach one or other of gdb or strace to a program? Is what I'm trying just not possible? Any suggestions appreciated.


Comments

  • Closed Accounts Posts: 7 sepia


    ok afaik there are two processes running when you start gdb.
    first I presume you do "gdb program", then enter whatever breakpoint, then "run".
    Ok so when you run "ps-aux" there should be two process,
    one should be "gdb prog" and the other should be "/home/satchmo/program",
    I think you are trying to trace through the "/home/satchmo/program" process which isn't attached to gdb. The "gdb prog" one is. I'm not 100% sure and I may be wrong.
    If all else fails just use "strace program" and step through it :D


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Originally posted by sepia
    If all else fails just use "strace program" and step through it :D
    Well that's exactly what I'm trying to do. :rolleyes: There's no way to use strace to step through a program, which is why I'm trying to attach it to the gdb-run process so I can then control when it steps to the next line.

    If I attach strace to the 'gdb prog' process, then I get all the system calls and signals that get sent by gdb, and the actual program's calls get lost in there which is hardly ideal. And the program I'm trying to trace through ("/home/satchmo/program" as you put it) is definitely the one being run by gdb - a simple 'ps afx' will show that.

    At the end of the ptrace man page, one of the reasons the 'EPERM' error (which I presume refers to 'operation not permitted') happens is because "the process may already be being traced", so I guess it may not be possible after all :mad:


  • Closed Accounts Posts: 7 sepia


    Originally posted by sepia
    If all else fails just use "strace program" and step through it

    Well that's exactly what I'm trying to do.

    what I mean't was get a pen and piece of paper and step through
    it methodically. It helps alot and probably will be ideal in your situation.
    But still it shouldn't be that hard to pick the syscalls from the signals
    as usually strace just sits there waiting for the input from the gdb prog. then again i am very drunk atm....

    :p


Advertisement