Query Windows PDB files with SQL.
$ pdbsql ntdll.pdb "SELECT name, rva FROM functions WHERE name LIKE '%Rtl%Heap%' ORDER BY rva"
+---------------------------+----------+
| name | rva |
+---------------------------+----------+
| RtlCreateHeap | 0x1A240 |
| RtlDestroyHeap | 0x1B890 |
| RtlAllocateHeap | 0x1C100 |
| RtlFreeHeap | 0x1D420 |
+---------------------------+----------+
PDB files are databases. Why not query them like one?
- Filter:
WHERE length > 1000 AND name NOT LIKE '%@%' - Sort:
ORDER BY rva DESC - Aggregate:
SELECT compiland, COUNT(*) FROM functions GROUP BY compiland - Join: Cross-reference functions with their source files and line numbers
- Script: Pipe results to other tools, generate reports, automate analysis
No SDK. No scripting runtime. Just SQL.
| Table | What's in it |
|---|---|
functions |
All functions with name, RVA, size, signature |
symbol_at(addr) |
TVF: innermost symbol containing an address (fast addr→symbol) |
publics |
Public symbols (exports, decorated names) |
udts |
Structs, classes, unions, deduplicated by default (size, member count) |
udt_records |
Raw per-compiland UDT rows behind the udts dedup |
udt_fields |
Data members: offset, type, bit position |
udt_methods |
Member functions: signature, is_virtual/is_pure |
enums |
Enumerations, deduplicated by default |
enum_records |
Raw per-compiland enum rows behind the enums dedup |
enum_values |
Enum members with values |
typedefs |
Type aliases |
data |
Global/static variables |
thunks |
Thunk symbols (import stubs, jump thunks) |
labels |
Label symbols |
base_classes |
Class inheritance (base/derived, offset) |
sections |
PE sections (.text, .data, .rdata) |
compilands |
Object files / translation units |
source_files |
Source file paths |
line_numbers |
Address-to-source mappings |
locals |
Local variables (per function) |
parameters |
Function parameters |
runtime_settings |
Writable: session controls (e.g. query_timeout_ms) |
# Clone with submodules
git clone --recursive https://github.com/0xeb/pdbsql.git
cd pdbsql
# Build (requires Windows + Visual Studio with DIA SDK)
cmake -B build
cmake --build build --config Release
# Run
build\bin\Release\pdbsql.exe your_file.pdb -iOne-shot query:
pdbsql test.pdb "SELECT name FROM functions WHERE length > 500"Machine-readable output / bulk export:
# TSV/CSV to stdout (the banner goes to stderr, so pipes stay clean)
pdbsql test.pdb -q "SELECT name,rva,length FROM functions LIMIT 100" --format tsv
# One-shot bulk export to disk (no HTTP, no padded table, column-aware).
# --format tsv|csv|jsonl; pick explicit columns for the fast path (no demangle).
pdbsql test.pdb -q "SELECT name,rva,length FROM functions" --format jsonl -o funcs.jsonl --query-timeout 0 --quiet
# --dump <table> is sugar for "SELECT * FROM <table>" (handy, but for functions it
# pulls the expensive undecorated column, so prefer explicit columns for a fast pull).
pdbsql test.pdb --dump sections --format csv -o sections.csv --quietThe CLI export streams to disk and is the simplest path for a one-off; a warm server is better when you export repeatedly (it skips process start and the one-time table warm-up, producing a byte-identical file).
WHERE rva = <addr> and WHERE name = '<exact>' are indexed lookups; substring
name LIKE '%…%' is a full walk. Selecting undecorated (the demangled name) is
the one expensive column — omit it for a fast bulk pull. That fixes the time
cost, not memory: a full walk of a large symbol table permanently commits several
GB regardless of which columns you select. Fine for a short-lived export; budget
for it if the process stays up.
Interactive mode:
pdbsql test.pdb -i
pdbsql> SELECT name, rva FROM udts WHERE name LIKE '%Manager%';
pdbsql> .schema functions
pdbsql> .quitHTTP server mode (expose PDB over HTTP):
# Terminal 1: Start server
pdbsql test.pdb --http 8080 --token secret123
# Terminal 2: Query over HTTP
curl -X POST http://localhost:8080/query -H "Authorization: Bearer secret123" --data-binary "SELECT * FROM sections"
# Stream a large result row-by-row: first byte in milliseconds and flat server
# memory, instead of waiting for the whole query and buffering it. Total time can
# be slightly higher than buffered. Use curl -N or the client will buffer anyway.
curl -N -X POST http://localhost:8080/query -H "X-XSQL-Stream: 1" --data-binary "SELECT name FROM publics"
# Bound a single request (ms; 0 = no limit), independent of the server default
curl -X POST http://localhost:8080/query -H "X-XSQL-Timeout: 5000" --data-binary "SELECT name,rva FROM functions"
# NDJSON stream: one JSON object per row per line (append rows to a file as they arrive)
curl -N -X POST http://localhost:8080/query -H "X-XSQL-Stream: ndjson" --data-binary "SELECT name,rva FROM functions"Queries are serialized — one slow query blocks every other client. The DIA session is not thread-safe, so the server runs queries one at a time: a millisecond query issued during a long scan waits its turn. On a multi-GB PDB an unscoped query can run for minutes, making it a server-wide stall. Always bound queries (
--query-timeoutat startup, or per-requestX-XSQL-Timeout), and run long unscoped scans on a separate instance.
/statusand/helpbypass the query executor, so health checks stay responsive — a green/statusdoes not prove the server can answer a query.
Bulk symbolization: batch the addresses.
symbol_ataccepts a correlated argument, so a whole address list resolves in one query — roughly 17x the throughput of one request per address. Two traps: sendContent-Type: text/plain(the form-urlencoded default returns a misleading HTTP 413 past ~8 KB), and usejson_each, notUNION ALL(which caps at 500 terms and reports the failure inside an HTTP 200).curl -N -X POST http://localhost:8080/query -H "Content-Type: text/plain" --data-binary \ "WITH addrs(a) AS (SELECT value FROM json_each('[4198400,4198512]')) SELECT a, (SELECT name FROM symbol_at(a)) FROM addrs"
Memory: budget several GB for a fully-exercised server on a multi-GB PDB. DIA caches symbols per session as queries touch them, so RSS grows with what you query and then converges — it does not leak. The first scan of any table pays a large shared base-index cost (a small table triggers it just as a large one does), and the UDT/Enum tables are by far the most expensive; everything after is essentially free, including repeat scans. A server that never queries UDT/Enum tables settles substantially lower. Buffered (non-streaming) responses add a transient on top.
Serving a large PDB: move the warm-up to startup. DIA builds its indexes lazily, on the first query that touches a given path, so the first request of each kind pays a large one-time cost that later identical requests do not. A long-lived server should pay that at boot rather than charging it to whichever request arrives first:
# Pre-enumerate the listed tables at startup (also works with --mcp)
pdbsql big.pdb --http 8080 --warm-tables functions,publics,udts
# Pay the line_numbers file_id index cost (10-18s on a large PDB) at startup
pdbsql big.pdb --http 8080 --warm-file-indexValid --warm-tables names: functions, publics, data, udts,
typedefs, enums, compilands.
A warm-up cannot be interrupted by a timeout. It produces no rows, so nothing polls the deadline — an
X-XSQL-Timeouton a cold first query reports the warm-up cost rather than the budget you asked for, and the query can appear to ignore its timeout when it is in fact working correctly. The work is never wasted (even a timed-out first query leaves the index built), so raise the bound for the first query rather than retrying it hoping for a cheaper outcome — or pre-warm at startup as above.
Address-range queries (WHERE rva > X AND rva < Y on functions/publics)
return every symbol in the window, including all of the symbols that share one
address (folded functions, public aliases), in rva order (ORDER BY rva DESC too).
The first one on a table in a session walks that table's addresses once and keeps
them sorted, which takes seconds on a large PDB; every later range query on the same
table is a lookup plus its own rows. WHERE rva = X stays a millisecond lookup of
one symbol. A range next to name = 'x', id = n or name LIKE 'prefix%' runs
that lookup and filters its rows by address instead.
# Cancel the in-flight query from another connection (it returns its partial rows)
curl -X POST http://localhost:8080/cancel -H "Authorization: Bearer secret123"
# Change the per-query timeout at runtime (default 60000 ms; 0 = no limit)
curl -X POST http://localhost:8080/query --data-binary "UPDATE runtime_settings SET value='30000' WHERE key='query_timeout_ms'"
# ...or seed it at startup (--query-timeout 0 disables the cap for a known-big dump)
pdbsql test.pdb --http 8080 --query-timeout 30Note:
--tokenguards the HTTP API only; the MCP endpoint (--mcp) is unauthenticated.The HTTP and MCP servers honor
runtime_settings.query_timeout_ms(default 60 s) per query —SELECT/UPDATE runtime_settingsto inspect or change it.--query-timeoutis a convenience that seeds the same setting at launch./statusis a cheap liveness check that never enumerates symbols, so it stays instant on very large PDBs.
MCP server mode (Model Context Protocol, for MCP clients):
# Random port 9000-9999, or pass an explicit port
pdbsql test.pdb --mcp
pdbsql test.pdb --mcp 9123The MCP server exposes two tools:
| tool | purpose |
|---|---|
pdbsql_query |
Run SQL directly against the PDB. |
pdbsql_help |
Return the complete pdbsql reference — every table and column, the query patterns that push down, and the performance traps on large PDBs. Takes no arguments. |
pdbsql_help returns the same document prompts/pdbsql_agent.md
that HTTP mode serves from GET /help; it is compiled into the binary, so the two
can never drift from the file. An MCP client should call pdbsql_help before
writing queries — on a large PDB the difference between a guided and an unguided
query is minutes, and a few documented query shapes do not complete at all.
pdbsql is a plain SQL CLI — it does not embed or run its own AI agent. To let an external agent or LLM (Claude, Copilot, or any assistant) drive pdbsql, point it at the tool two ways:
- As a system prompt: feed
prompts/pdbsql_agent.mdto your model as its system/instruction prompt. It documents the full SQL schema, every table and column, and worked query patterns, so the model can translate natural-language questions into pdbsql SQL and run them via-q/--http/--mcp. - Over MCP: start
pdbsql file.pdb --mcpand connect any MCP client (see MCP server mode above). The client's own model does the reasoning; pdbsql exposespdbsql_queryto execute SQL andpdbsql_helpto fetch the same reference on demand — so an MCP client does not need the system-prompt step above, it can pull the document itself. - Over HTTP:
GET /helpreturns the REST mechanics followed by that same reference.
Triage a crash dump:
-- Symbol at the crash address — O(1) containment lookup (any kind), not a full scan
SELECT name, kind, rva, length FROM symbol_at(0x12345);Understand binary structure:
-- Largest functions (complexity indicators)
SELECT name, length FROM functions ORDER BY length DESC LIMIT 20;
-- Executable sections with their names, sizes and flags
SELECT number, name, rva, length, characteristics, readable, writable, executable FROM sections;Reverse engineering prep:
-- Find source files contributing to a given compiland
SELECT sf.filename, c.name AS compiland
FROM source_files sf
JOIN line_numbers ln ON ln.file_id = sf.id
JOIN compilands c ON c.id = ln.compiland_id
WHERE sf.filename LIKE '%crypto%'
GROUP BY sf.filename, c.name;
-- Virtual function tables (C++ RE)
SELECT u.name, COUNT(m.id) as vtable_size
FROM udts u
JOIN udt_fields m ON u.id = m.udt_id
WHERE m.name LIKE '%vftable%'
GROUP BY u.name;Diffing binaries:
-- Export function signatures for comparison
SELECT name, length, printf('0x%X', rva) as addr
FROM functions
ORDER BY name;
-- Save to file, diff against another versionRequirements:
- Windows (DIA SDK is Windows-only)
- Visual Studio 2019+ with C++ workload (includes DIA SDK)
- CMake 3.20+
Steps:
git clone --recursive https://github.com/0xeb/pdbsql.git
cd pdbsql
# Initialize submodules (libxsql)
git submodule update --init --recursive
cmake -B build
cmake --build build --config Release
Build options:
PDBSQL_WITH_HTTP=ON(default): HTTP REST serverPDBSQL_WITH_MCP=ON(default): MCP server (SSE), fetches fastmcpp
If pdbsql saves you time, a donation funds the next release, and a star helps others find it.
Bug reports with a minimal reproduction are just as valuable.
In short: you may read, build, evaluate, benchmark, package, and use unmodified pdbsql, including commercially, if you preserve notices and follow the license terms. You may fork or patch it to prepare bug fixes, optimizations, features, tests, or documentation improvements for contribution back within the license's contribution-purpose rules.
You may not maintain a divergent private fork, port, rebrand, clone, API-compatible replacement, competing implementation, or use pdbsql as AI input to recreate or improve a derivative implementation without prior written permission from Elias Bachaalany. Independent implementations that are not copied from, materially derived from, or substantially informed by pdbsql in the license's defined sense are not prohibited.
Permission requests: open a GitHub issue at 0xeb/pdbsql/issues.
If pdbsql materially informs a distributed project, preserve the human origin: credit pdbsql and Elias Bachaalany visibly in your README/docs and in About/credits UI when applicable. The license includes an examples/FAQ section for common allowed and permission-required uses. Third-party dependencies (libxsql, the Windows Debug Interface Access (DIA) SDK, and their transitive dependencies) remain under their own licenses.
See the full Human-Origin Source License v1.0.
Releases up to v0.0.3 remain under the MPL-2.0 they were published with; v0.0.4 and all subsequent releases are under the Human-Origin Source License v1.0.
pdbsql is part of a family of tools that expose different binary-analysis and debug-information platforms through the same SQL surface, all built on the shared libxsql virtual-table framework. A query you learn against one tool largely carries over to the others.
Reverse-engineering platforms
- idasql — IDA Pro databases as SQL.
- bnsql — Binary Ninja databases as SQL.
- ghidrasql — Ghidra databases as SQL.
Debug info & compiler data
Core
- libxsql — the C++ SQLite virtual-table framework every tool above is built on.