Find the answer to your Linux question:
Results 1 to 7 of 7
Hey. I have a shell script that first runs gdb debuger, executes commands and writes results in a .txt files. So I have my first shell file written like so: ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    19

    Error handling in shell

    Hey.

    I have a shell script that first runs gdb debuger, executes commands
    and writes results in a .txt files.

    So I have my first shell file written like so:

    gdb -x gdb_commands.sh a.out > text.txt

    With objdump I got names of classes which
    i want to print in text.txt. So i put Ptype before them and made gdb_commands.sh.

    In my gdb_commands.sh I have:
    break main
    run
    Ptype CClassA #a class retrieved from objdump that is going to be printed in text.txt
    Ptype CClassB # another class...
    Ptype CClassC
    Ptype __gnu_cxx # class I got from objdump but gdb doesnt find it.
    Ptype CClassD #another class i want

    This is what my script does... it succesfully prints first 3 classes
    but at __gnu_cxx it prints an error and stops gdb_commands.sh script.
    It doesnt quit from gdb debuger it just exits the gdb_comands.sh script.

    How can I make it, so it WON'T exit the script or how
    can I skip classes that are not found?

    I get this error for gdb_commands.sh:
    "Error in sourced command file:
    No symbol "_gnu_cxx" in current context"

    Please help me I realy want to get this to work.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Enter the following line at the bash prompt, and all will be revealed.
    Code:
    man expect
    If man pages are not installed on your system, google this:
    Code:
    man expect linux
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    19
    TNx for the tip.

    So with expect I can make a script that will execute commands and wont
    be botherd by errors?

    But I dont know how to write a expect script I didnt find any tutorials on it.

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    So with expect I can make a script that will execute commands and wont
    be botherd by errors?
    No, but you can build an expect script which sends a command to gdb for each class, and just blindly keeps going.
    I dont know how to write a expect script I didnt find any tutorials on it.
    google this:
    expect tutorial
    Actually, I thought of two other alternatives, if you decide not to use expect:
    1. Loop through all your class names. For each one, build a file that looks like this:
      Code:
      break main
      run
      Ptype single_class_name
      and run gdb against that command file. Just let the loop run, and it should blindly go through the good and the bad.
    2. If you still want to run gdb just once, don't include any class names that begin with underscore ("_").
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Just Joined!
    Join Date
    Feb 2008
    Posts
    19
    What do you mean loop through?

    you mean i should write first script like this:

    Code:
    gdb -x commands1.sh a.out > text.txt
    gdb -x commands2.sh a.out > text.txt
    gdb -x commands3.sh a.out > text.txt
    gdb -x commands4.sh a.out > text.txt
    .
    .
    .
    and then commands1.sh would be
    Code:
    break main
    run
    Ptype CClassA
    quit
    commands2.sh
    Code:
    break main
    run
    Ptype CClassB
    quit
    and so on....??

    Well i did though of that and the problem is that when script in gdb stops
    at Ptype __gnu_cxx it doesnt exit gdb and so you cant execute another
    command in first script until gdb is closed.

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    the problem is that when script in gdb stops at Ptype __gnu_cxx it doesnt exit gdb
    Enter the following line at the bash prompt.
    Code:
    man gdb
    If man pages are not installed on your system, google this:
    Code:
    man gdb linux
    Within the man page, look for the -batch option.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  7. #7
    Just Joined!
    Join Date
    Feb 2008
    Posts
    19
    -batch did the trick thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...