Solved

gdb script not working with -k and -wcore and -x options in new version of gdb, Is there an alternate meathod to count the number of file descriptors in use?

Posted on 2010-11-24
1
1,058 Views
Last Modified: 2013-11-22
This works in IPSO 4.2:
#!/bin/sh

FILE=/tmp/patch.$$
cat << _EOF > $FILE
x/1d (&nfiles)
quit
_EOF
NUMFD=`gdb -k -wcore -batch -x $FILE /image/current/kernel /dev/mem \ | grep nfiles | awk ' { print $3 } '`

echo "There are $NUMFD file descriptors in use"
rm $FILE

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
In IPSO 6.2 I get:
# ./numdescriptors.sh
gdb: unrecognized option `-k'
Use `gdb --help' for a complete list of options.
There are  file descriptors in use


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Options for IPSO 6.2:
# gdb --help
This is the GNU debugger.  Usage:

    gdb [options] [executable-file [core-file or process-id]]
    gdb [options] --args executable-file [inferior-arguments ...]


  --args             Arguments after executable-file are passed to inferior
  --[no]async        Enable (disable) asynchronous version of CLI
  -b BAUDRATE        Set serial port baud rate used for remote debugging.
  --batch            Exit after processing options.
  --cd=DIR           Change current directory to DIR.
  --command=FILE     Execute GDB commands from FILE.
  --core=COREFILE    Analyze the core dump COREFILE.
  --pid=PID          Attach to running process PID.
  --dbx              DBX compatibility mode.
  --directory=DIR    Search for source files in DIR.
  --epoch            Output information used by epoch emacs-GDB interface.
  --exec=EXECFILE    Use EXECFILE as the executable.
  --fullname         Output information used by emacs-GDB interface.
  --help             Print this message.
  --interpreter=INTERP
                     Select a specific interpreter / user interface
  --mapped           Use mapped symbol files if supported on this system.
  --nw               Do not use a window interface.
  --nx               Do not read .gdbinit file.
  --quiet            Do not print version number on startup.
  --readnow          Fully read symbol files on first access.
  --se=FILE          Use FILE as symbol file and executable file.
  --symbols=SYMFILE  Read symbols from SYMFILE.
  --tty=TTY          Use TTY for input/output by the program being debugged.
  --tui              Use a terminal user interface.
  --version          Print version information and then exit.
  -w                 Use a window interface.
  --write            Set writing into executable and core files.
  --xdb              XDB compatibility mode.

For more information, type "help" from within GDB, or consult the
GDB manual (available as on-line info or a printed manual).
Report bugs to "bug-gdb@gnu.org".

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Options for IPSO 4.1:
# gdb --help
GDB 4.16 (i386-unknown-freebsd), Copyright 1996 Free Software Foundation, Inc.
This is the GNU debugger.  Usage:
    gdb [options] [executable-file [core-file or process-id]]
Options:
  --help             Print this message.
  --quiet            Do not print version number on startup.
  --fullname         Output information used by emacs-GDB interface.
  --epoch            Output information used by epoch emacs-GDB interface.
  --batch            Exit after processing options.
  --nx               Do not read .gdbinit file.
  --tty=TTY          Use TTY for input/output by the program being debugged.
  --cd=DIR           Change current directory to DIR.
  --directory=DIR    Search for source files in DIR.
  --command=FILE     Execute GDB commands from FILE.
  --symbols=SYMFILE  Read symbols from SYMFILE.
  --exec=EXECFILE    Use EXECFILE as the executable.
  --se=FILE          Use FILE as symbol file and executable file.
  --core=COREFILE    Analyze the core dump COREFILE.
  -b BAUDRATE        Set serial port baud rate used for remote debugging.
  --mapped           Use mapped symbol files if supported on this system.
  --readnow          Fully read symbol files on first access.
  --nw               Do not use a window interface.
  --kernel           Enable kernel debugging.
  --wcore            Make core file writable (only works for /dev/mem).
                     This option only works while debugging a kernel !!

For more information, type "help" from within GDB, or consult the
GDB manual (available as on-line info or a printed manual).
0
Comment
Question by:Dooglave
1 Comment
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 500 total points
ID: 34211567
I don't have a kernel built with debug symbols, so I couldn't try this properly. But on a modern system it should work to miss out -k and -wcore and use /dev/core instead of /dev/mem.
My "modern" system is Linux 2.6.32 and gdb 7.1.
I found an older gdb (rev 5.3) but even that didn't recognise -wcore. If your gdb recognises -wcore then you could leave it (but you won't know whether it does until you omit -k).
You will know that /dev/mem is wrong if gdb reports it is not a core file
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now