After upgrade gdb won't attach to process


I just recently upgraded from 10.04 to 11.04 and gdb won't allow me to attach to processes anymore I get the error

Attaching to process 10144 Could not attach to process. If your uid matches the uid of the target process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf ptrace: Operation not permitted.

How do I fix this so that I can debug again without sudo?

In Maverick Meerkat (10.10) Ubuntu introduced a patch to disallow ptracing of non-child processes by non-root users - ie. only a process which is a parent of another process can ptrace it for normal users - whilst root can still ptrace every process. Hence why you can use gdb to attach via sudo still.

You can temporarily disable this restriction (and revert to the old behaviour allowing your user to ptrace (gdb) any of their other processes) by doing:

echo 0 | sudo tee...
0 0

If you prefer to leave /proc/sys/kernel/yama/ptrace_scope set to its default value of 1, then as a workaround you could consider using gdb to run the program you want to debug. You can then bring up the debugger simply by pressing ^C. For example, to debug to the (boring) program sleep 60, do the following:

$ gdb -q sleep -ex 'run 60'

Here is a complete example.

$ gdb -q sleep -ex 'run 60' Reading symbols from sleep...(no debugging symbols found)...done. Starting program: /bin/sleep 60 ^C Program received signal SIGINT, Interrupt. 0x00007ffff7ad5d60 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:81 81 ../sysdeps/unix/syscall-template.S: No such file or directory. (gdb) backtrace #0 0x00007ffff7ad5d60 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:81 #1 0x0000000000403cd7 in ?? () #2 0x0000000000403b88 in ?? () #3 0x00000000004016c9 in ?? () #4 0x00007ffff7a35ec5 in __libc_start_main (main=0x401540, argc=2, argv=0x7fffffffea08, init=,...
0 0

I can reproduce that with a simple test app, sans WatchKit. The app consists of a NSTimer that prints "Timer fired" every second. (This code is 100% correct ;). Nothing shows in the log after I have manually attached to the process.
As far as I know NSLog outputs to stderr, I guess attaching the debugger does not redirect stderr to the Xcode terminal.

If you are okay with using the console app or the terminal to look at your logs you can do that. iOS8 stores simulator logs in ~/Library/Logs/CoreSimulator/. In this directory you will find a system.log, which contains all your NSLog output.

You can look at it in terminal (cat, grep, tail), or open it in the

Apple confirms that (at least for GDB) in Technical Note TN2239: iOS Debugging Magic.

Console Output

Many programs, and indeed many system frameworks, print debugging messages to stderr. The destination for this output is ultimately controlled by the program: it can redirect...

0 0
Home < Documentation < Nightly < Developers < Tutorials < Debug Instructions


The executable Slicer application Slicer-Superbuild/Slicer-build/Slicer (or Slicer.exe) is the launcher of the real application binary Slicer-Superbuild/Slicer-build/bin/SlicerApp-real.


Analyze a segmentation fault

$ ulimit -c unlimited $ ./Slicer ... make it crash $ ./Slicer --gdb ./bin/SlicerApp-real (gdb) core core (gdb) backtrace ...

GDB debug with launch arguments

The Slicer app launcher provides options to start other programs with the Slicer environment settings.

--launch []: executes an arbitrary program. For example, Slicer --launch /usr/bin/gnome-terminal starts gnome-terminal (then run GDB directly on SlicerQT-real) --gdb: runs GDB then executes SlicerQT-real from within the debugger environment.

GDB debug by attaching to running process [RECOMMENDED]

Starting with Ubuntu 10.10, ptracing of non-child processes by non-root users as...
0 0

>Number: 2347
>Category: gdb
>Synopsis: gdb 6.7 can't attach to process
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: unassigned
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Thu Oct 25 18:48:01 UTC 2007
>Originator: Paul M. Dubuc
>Release: 6.7

uname -a

Linux mrldev32 2.6.9-42.0.10.ELlargesmp #1 SMP Fri Feb 16 17:25:40 EST 2007 x86_64 GNU/Linux

cat /etc/redhat-release
Red Hat Enterprise Linux AS release 4 (Nahant Update 4)

gdb32 --version
GNU gdb 6.7
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"...

0 0

I recently upgraded from Mac OS X 10.7 to 10.9. As gdb is no longer supported in OS X, I installed GNU gdb via macports. Before being able to use it, I had to codesign it as described here. Now I can use gdb as debugger but I have problems in setting up breakpoints when attaching to a process. I will make an example for you. I took this sample C code

#include #include void f() { printf("f()\n"); } int main() { printf("sleeping 30 seconds...\n"); sleep(30); printf("invoking f()\n"); f(); }

and compile it with

gcc -g a.c

If I now try to debug by doing

gdb a.out

and running it within gdb, the outcome is the following (as expected)

GNU gdb (GDB) 7.6 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as...
0 0

I am trying to setup the gdb debugger in eclipse to attach to a remote program. Here is the setup that I am using:

For the development PC (dev), I am using Eclipse Mars on a Windows 7 PC. Eclipse is set to use the GCC/G++ cross compiler and gdb as the remote debugger. I am using Sourcery CodeBench Lite as the development tool in windows.

dev> gdb --version dev> GNU gdb (Sourcery CodeBench Lite 2014.05-25)

The target PC is a RHEL 7, where I use gdbserver so that I can debug my application remotely.

target> gdbserver --version target> GNU gdbserver (GDB) Red Hat Enterprise Linux 7.6.1-64.el7 Copyright (C) 2013 Free Software Foundation, Inc.

I have two debug configuration in eclipse, one for remote debug and another for attaching to a remote program that is running in target PC. I have no problem debugging my program using the remote debug configuration, however, when I try to attach to the remote program, I get the following...

0 0

Supported on windows

Supported on linux

Not supported on embedded

Supported on android

Attaches GDB to a running process


attach [PID]


PID Specifies the process identifier of the process to attach to.


To continue the process after you have attached to it use the continue command. If you use the run command instead, the process will be restarted.


When you attach to processes with GDB, the following restrictions are applied:

In order to attach to processes from different Linux terminals you need to be running as root. In order to attach to processes on Windows machine you need to run GDB as Administrator. You cannot attach two instances of GDB to the same process. You cannot attach GDB to a Windows process that is already being debugged by native Visual Studio debugger.


In the following example we attach GDB to a running Linux...

0 0
Debugging with GDB: Attach

4.7 Debugging an Already-running Process

attach process-id

This command attaches to a running process—one that was started outside GDB. (info files shows your active targets.) The command takes as argument a process ID. The usual way to find out the process-id of a Unix process is with the ps utility, or with the ‘jobs -l’ shell command.

attach does not repeat if you press RET a second time after executing the command.

To use attach, your program must be running in an environment which supports processes; for example, attach does not work for programs on bare-board targets that lack an operating system. You must also have permission to send the process a signal.

When you use attach, the debugger finds the program running in the process first by looking in the current working directory, then (if the program is not found) by using the source file search path (see Specifying Source Directories). You can also use the file...

0 0

I read through GDB Monitor commands in CLion providing good insight, but I am having a slightly different issue:

My environment:

Target: ARM Cortex M4 (STM32F401RE) ST-UTIL gdb server ( arm-none-eabi-gdb 7.7.1+dfsg-5+8~bpo8+1 CLion 2016.3.2 Build #CL-163.10154.43 Debian 8

In the GDB Remote Debug config panel, I've set:

GDB: /usr/bin/arm-none-eabi-gdb Symbol file: /home/malachi/temp/mbed_test/mbed-os-program/BUILD/NUCLEO_F401RE/GCC_ARM/mbed-os-program.elf

From CLion, no matter what I do, I consistently get this for Console:

Cannot configure GDB defaults: No symbol table is loaded. Use the "file" command. Debugger connected to localhost:4242

I've tried brute forcing 'file' with a .gdbinit but gdbinit seems ignored

Furthermore, it does indicate a connection to st-util running remotely, but I am unable to execute any commands (breakpoints, stepping, pause, etc) except for terminate - which does seem to terminate...

0 0

I have just moved from Ubuntu 10.04 to the new version of 11.04 and when I try to debug with ddd/gdb I cannot set anymore breakpoints nor see the flow while the debugger is executing my program.

I receive error messages saying

(gdb)b MyFile.cpp:27 No line 27 in file "MyFile.cpp".

When I start running my application calling r I also can see the following text message that looks to me related to my issue. The debuggers traps all assertions but I cannot stop at any point.

(gdb) r BFD: /lib/x86_64-linux-gnu/ invalid relocation type 37 BFD: BFD (GNU Binutils) assertion fail elf64-x86-64.c:278 BFD: /lib/x86_64-linux-gnu/ invalid relocation type 37 BFD: BFD (GNU Binutils) assertion fail elf64-x86-64.c:278

If I want to see the file, the debuggers open the file with me but I receive the following error message

(gdb) list MyFile.cpp:27 Line number 27 is out of range for "MyFile.cpp"....

0 0

Moving from dbx to gdb:

I would like to permanently suppress the information gdb prints out on my terminal while attaching to a running process in its entirety. Does anyone know how to do that? Thank you for any help.

Sample (64-bit CentOS 6.6) session:

gdb -p 12345 Attaching to process 12345 Reading symbols from /some/path/to/my/ELF executable...done. Reading symbols from /some/other/path/to/my/ Loaded symbols for /some/other/path/to/my/ [New LWP 12345] [New LWP 12345] [New LWP 12345] [New LWP 12345] [Thread debugging using libthread_db enabled] 0x000000338a6aca3d in nanosleep () from /lib64/ Missing separate debuginfos, use: debuginfo-install ...

In reality there are multiple screens of the above 'Reading' and 'Loading' entries which I am suppressing manually for sanity sake. There are also 4 100-character long lines of complaints about "Missing separate debuginfo" which I am also manually suppressing for the...

0 0

I am having the same issue:

root# gdb

GNU gdb 6.3.50-20050815 (Apple version gdb-1708 + patches v0.4) (Mon Apr 16 00:53:47 UTC 2012)

Copyright 2004 Free Software Foundation, Inc.

GDB is free software, covered by the GNU General Public License, and you are

welcome to change it and/or distribute copies of it under certain conditions.

Type "show copying" to see the conditions.

There is absolutely no warranty for GDB. Type "show warranty" for details.

This GDB was configured as "arm-apple-darwin".

warning: Unrecognized osabi 0 in arm_set_osabi_from_host_info

(gdb) attach --waitfor GDB-Demo

Waiting for process 'GDB-Demo' to launch.

Attaching to process 7289.

warning: error on line 221 of "/Volumes/Builds2/BuildRoot/SourceCache/gdb/gdb-1708/src/gdb/macosx/macosx-nat-infthread.c" in function "kern_return_t modify_trace_bit(thread_t, int)": (os/kern) invalid argument...

0 0
Debugging with GDB - Running Programs Under GDB

Go to the previous, next section.

When you run a program under GDB, you must first generate debugging information when you compile it. You may start it with its arguments, if any, in an environment of your choice. You may redirect your program's input and output, debug an already running process, or kill a child process.

In order to debug a program effectively, you need to generate debugging information when you compile it. This debugging information is stored in the object file; it describes the data type of each variable or function and the correspondence between source line numbers and addresses in the executable code.

To request debugging information, specify the `-g' option when you run the compiler.

Many C compilers are unable to handle the `-g' and `-O' options together. Using those compilers, you cannot generate optimized executables containing debugging information.

GCC, the GNU C...

0 0
0 0