• Stars
    star
    197
  • Rank 197,722 (Top 4 %)
  • Language
    C
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple, single-file, dependency-free GDB stub that can be easily dropped in to your project.

gdbstub

This is a simple, single-file1 GDB stub library that can be easily dropped in to your project to allow you to debug a target platform using GDB (or another application which supports remote GDB targets). It has no library dependencies (such as libc) and requires just standard tools to build.

Protocol

Communication between the stub and the debugger takes place via the GDB Remote Serial Protocol.

Usage

In some .c file in your project:

/* Define to enable bare metal x86 support, or define your own architecture */
#define GDBSTUB_ARCH_X86

/* Enable function definitions */
#define GDBSTUB_IMPLEMENTATION

#include "gdbstub.h"

void _start(void) {
	dbg_sys_init(); /* Setup, wait for debugger on serial port  */
}

See gdbstub.c for example usage.

Architecture Support

  • GDBSTUB_ARCH_MOCK: A mock architecture for testing
  • GDBSTUB_ARCH_X86: Bare-metal x86 (32-bit). You'll also need interrupt handlers (so not .

Porting

This was originally developed for embedded x86 systems, but it's fairly modular. With a little effort, it can be easily ported to other platforms.

I recommend copying the mock architecture implementation and adjusting it to fit your platform's needs accordingly.

PR's for other platforms are welcome!

Building

By default, running make produces a gdbstub program. This is simply a stub for a mock architecture (just a handful of registers and some memory) running inside a normal program that communicates over stdio.

A stub intended for bare metal x86 machines can be built with make ARCH=x86. This produces an ELF binary gdbstub.elf that will hook the current IDT (to support debug interrupts) and break.

Additionally, a simple flat binary gdbstub.bin is created from the ELF binary. The intent for this flat binary is to be easily loaded into memory and jumped to.

x86 Demo

In gdbstub.c there is a simple function that's used for demonstration and testing. To use it, build the stub with:

$ make ARCH=x86 INCLUDE_DEMO=1

Then, to test the GDB stub out, launch an instance of the full-system emulator QEMU as follows:

qemu-system-i386 -serial tcp:127.0.0.1:1234,server -display none -kernel gdbstub.elf

This will launch QEMU, create a virtual machine with a virtual serial port that can be connected to through local TCP port 1234, then load and run the stub executable inside the virtual machine.

You can then launch your local GDB client to get your GDB client to connect to the virtual serial port and begin debugging the demo application:

$ gdb
(gdb) symbol-file gdbstub.elf
(gdb) target remote 127.0.0.1:1234
(gdb) b simple_loop
(gdb) layout split
(gdb) c

For example, step a couple of times and print out the value of x:

(gdb) s 3
(gdb) p/x x
$1 = 0xdeadbeef

License

This software is published under the terms of the MIT License. See LICENSE.txt for full license.

Matt Borgerson, 2016-2022

Footnotes

  1. The main protocol bits and most architecture support is in a single file: gdbstub.h. Some platform files might also be required depending on your use case. โ†ฉ

More Repositories

1

xemu

Original Xbox Emulator for Windows, macOS, and Linux (Active Development)
C
1,384
star
2

mdec

Decompilation as a Service. Explore multiple decompilers and compare their output with minimal effort. Upload binary, get decompilation.
Python
451
star
3

TrayPlay

An app for macOS that lives in your menu bar and lets you easily control iTunes or Spotify, without interrupting your workflow.
Objective-C
143
star
4

fatx

Original Xbox FATX Filesystem Library, Python bindings, FUSE driver, and GUI explorer
C
110
star
5

l2tunnel

Open-source, cross-platform L2 tunneling for game consoles and other devices
C
49
star
6

blynclight

Open-source control software for the Embrava Blynclight
Python
37
star
7

dc27-dooom

Port of the classic first-person-shooter DOOM to Xbox for DEFCON 27 CTF
Shell
26
star
8

textureatlas

A simple, cross-platform Python-based tool and C library for creating and using a texture atlas in your application or game. Distributed under the terms of the MIT license.
Python
24
star
9

genconfig

Automatic runtime configuration / settings system for your C/C++ application. Load from TOML configs into a generated C struct and back again with minimal effort.
C++
22
star
10

xqemu-kernel

An open-source Xbox kernel alternative, designed for use with XQEMU.
C
21
star
11

basic_sdl2_gl

No-fuss Modern SDL2/OpenGL/GLEW Boilerplate
C
19
star
12

spotify-playlist-from-csv

Create playlists in Spotify using Python, libspotify, and pyspotify.
Python
19
star
13

jit

A little just-in-time compiler thing
C
18
star
14

xbox-includes

GPL Original Xbox kernel and library includes, sourced from Cxbx-Reloaded, Wine, OpenXDK
C
18
star
15

bintrace

Fast program tracing and analysis
Python
16
star
16

xbeeprom

Simple tool to edit Xbox EEPROMs
C++
15
star
17

pyxbe

Python 3 library to read and write XBE files, the executable file format for the original Xbox game console
Python
14
star
18

xemu-hdd-image

Copyright-Free Xbox HDD Image
C
13
star
19

OpenXBOX

Defunct proof of concept project--check out xemu!
12
star
20

xsm64

C
10
star
21

xemu-website

xemu.app website sources
SCSS
7
star
22

cromwell

GPL Xbox BIOS replacement
C
6
star
23

Pad

Sublime Text Plug-In to Add Padding to Lines
Python
5
star
24

xemu-test

xemu Automated Tests
Python
4
star
25

GoTruncateHtml

A Go library for truncating HTML and optionally appending an ellipsis.
Go
4
star
26

baremetal

"Bare Metal" C/C++ Demo Code
C
4
star
27

xbtests

Tests for the original Xbox
C
3
star
28

MarkdownViewer

A simple Markdown file viewer written in Python.
Python
3
star
29

MXMarqueeText

A simple OS X / Cocoa scrolling text (marquee) control.
Objective-C
3
star
30

xemu-test-agent

Python
1
star
31

simple-lru

Simple LRU cache
C
1
star
32

test-xemu-s3tc-volume-compress

C
1
star
33

mips_toolchain

Simple MIPS toolchain setup using dockcross
C
1
star
34

pyfuzzer

Like AFL, but worse. Python+QEMU-user based fuzzer
Python
1
star
35

PyXbSymbolDatabase

Python bindings to the "Xbox Symbol Database"
Python
1
star