2

I am new to debugging an assembly code under gdb.Therefore, I have some question;

  • How can I run my assembly code (At virtual place ) without actually running it ?
  • If it needs a value, how can I insert a value to see how it works for each case in switch statement?

    ex: I couldnot give example on assembly so I give it in c.

        scanf ( "%d",&y);
        while ( y ) {
             ...
             scanf( "%d", &x);
             switch ( x ) {
    
             case 1: ...
             case 2: ...
             case 3: ...
             }
    
         }
    
  • If I need, how can I know what value is stored in a register ?

  • How can I print out all display to my .txt file ? In other words, assume I have started my program and it runs with no break point and then I want print this display to .txt file. So, I can work on paper. As You know, paper is more powerful than computer :)

I know some of you will say "go and read gdb tutorial or man page".But, I could not find any good tutorials, with example to explain how a command works. My brain only works when my eyes see example :)

Platform is Linux Tool is terminal/console

EDIT : Please give me a good website including good documentation, of course If you know

Give me documentation of "how to [catch] fish", "not how to eat fish"

1
  • feel free when you have a command Commented Oct 20, 2011 at 17:30

2 Answers 2

1

How can I run my assembly code without actually running it ?

Umm, err, what?!

If it needs a value, how can I insert a value to see how it works for each case in switch statement?

set whatever = some expression

Remember that registers have a $ sigil (e.g: $eax).

If I need, how can I know what value is stored in a register ?

For all registers:

info reg

For a specific register

info reg $eax

or

p $eax

or

p/x $eax

etc...

How can I print out all display to my .txt file ? In other words, assume I have started my program and it runs with no break point and then I want print this display to .txt file. So, I can work on paper. As You know, paper is more powerful than computer :)

set logging file foobar.out
set logging on
Sign up to request clarification or add additional context in comments.

1 Comment

for umm, err, what?, Assume my program is doing its job in internet. However, I don't want, when I run my program in gdb, it sends a message to server. I am trying to figure out where bug hides.I may run it many times. Try to understand me :)In other words, It may run in virtual place but I don't want that program send message to web.
1

Look at this page: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka12961.html - it's for ARM assembler, most should fit for all assemblers. You can set the program counter to the desired instruction, put values into registers, view registers, view memory etc. Don't print it out, we're out of trees almost already.

1 Comment

+1 Although a link like: chemie.fu-berlin.de/chemnet/use/info/gdb/gdb_12.html#SEC91 would have been more specific to the OP's question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.