# Breakpoints in gdb using int3

DevFeed: [Breakpoints in gdb using int3](<https://devfeed.tech/articles/breakpoints-in-gdb-using-int3-21551.md>)

Original publisher: [Read original article](<http://lackingrhoticity.blogspot.com/2010/05/breakpoints-in-gdb-using-int3.html>)

Author: Mark Seaborn (noreply@blogger.com)

Published: 2010-05-01T11:59:00Z

Content type: tutorial

Language: en

Sources: [Mark Seaborn](<https://devfeed.tech/sources/mark-seaborn.md>)

Topics: [debugging](<https://devfeed.tech/topics/debugging.md>), [Assembly](<https://devfeed.tech/topics/assembly.md>), [x86](<https://devfeed.tech/topics/x86.md>), [Linux](<https://devfeed.tech/topics/linux.md>), [Ubuntu](<https://devfeed.tech/topics/ubuntu.md>)

Tags: [assembly](<https://devfeed.tech/tags/assembly.md>), [breakpoint](<https://devfeed.tech/tags/breakpoint.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [debugging-tools](<https://devfeed.tech/tags/debugging-tools.md>), [gdb](<https://devfeed.tech/tags/gdb.md>), [glibc](<https://devfeed.tech/tags/glibc.md>), [linux](<https://devfeed.tech/tags/linux.md>), [memory](<https://devfeed.tech/tags/memory.md>), [signal](<https://devfeed.tech/tags/signal.md>), [x86](<https://devfeed.tech/tags/x86.md>), [x86-64](<https://devfeed.tech/tags/x86-64.md>)

## AI overview

This article explains how inserting the x86 int3 instruction, for example through __asm__("int3"), can trigger a breakpoint while debugging with gdb. It notes that int3 raises SIGTRAP, allowing inspection of registers, memory, and the call stack under gdb, and can be useful when setting a source-line breakpoint is impractical, such as within inline assembly.

## Source excerpt

Here is a useful trick I discovered recently while debugging some changes to the seccomp sandbox. To trigger a breakpoint on x86, just do: __asm__("int3"); Then it is possible to inspect registers, memory, the call stack, etc. in gdb, without having to get gdb to set a breakpoint. The instruction triggers a SIGTRAP, so if the process is not running under gdb and has no signal handler for SIGTRAP, the process will die. This technique seems to be fairly well known, although it's not mentioned in the gdb documentation. int3 is the instruction that gdb uses internally for setting breakpoints. Sometimes it's easier to insert an int3 and rebuild than get gdb to set a breakpoint. For example, setting a gdb breakpoint on a line won't work in the middle of a chunk of inline assembly. My expectations of gdb are pretty low these days. When I try to use it to debug something low level, it often doesn't work, which is why I have been motivated to hack together my own debugging tools in the past. For example, if I run gdb on the glibc dynamic linker (ld.so) on Ubuntu Hardy or Karmic, it gives: $ gdb /lib/ld-linux-x86-64.so.2 ... (gdb) run Starting program: /lib/ld-linux-x86-64.so.2 Cannot access memory at address 0x21ec88 (gdb) So it's nice to find a case where I can get some useful information out of gdb.