Add multiple breakpoint handlers: conditional, ignore-count, logpoint

Backend (src/debugger.h/.cpp): Breakpoint gains kind (plain/conditional/
logpoint), condition (-break-condition), ignore_count (-break-after),
log_message and group. Logpoints are gdb dprintf breakpoints created via
-interpreter-exec console; the message template supports {expr} (%d),
{s:expr} (%s), {f:expr} (%f), {x:expr} (%#x), {p:expr} (%p) via
logpoint_to_printf(). New API: stage/add_breakpoint_opts(),
update_breakpoint() (live: delete + re-insert, new id in out; staged:
in place). refresh_breakpoints() reads type/cond/ignore/times from
-break-list and merges the log template/group back from our records;
start() re-applies saved breakpoints with full handler options. Bad
conditions are rejected and the breakpoint rolled back. Persistence
format extends to location|enabled|kind|condition|ignore|log_message|
group with backslash escaping; old two-field lines still load as plain.

UI (src/debugger_ui.cpp): breakpoint list shows Type, Condition,
Ignore and Message columns; Add... / Edit... open a handler dialog
(type, condition, ignore spin, log message, group); staged entries
are toggled/removed/edited by list position (they share id 0).

Tests (tests/debugger/dbg_harness.cpp): console 31 -> 37
(conditional fires only at i==2 with hits==1; ignore=2 skips to i==2
with hits==3; logpoint prints LOG i=0/1/2 and never stops; template
conversion incl. % escaping and bad-template rejection; live
plain->conditional update; persistence round-trip incl. | escaping
and old-format load; bad condition rejected with no bp left).
GTK 5 -> 7 (logpoint in callback prints, never stops; conditional
in callback fires). Full debugger_tests.sh ALL PASS, matrix 20/1
(chart-pro-render known Xvfb pixel flake), self-test 29 PASS.
This commit is contained in:
root committed 2026-11-25 11:58:31 -05:00
1 parent 7828ced3d6
commit b71ba03d79
4 files changed
+975 -33

No files matched your search

+401 -19
View File
@@ -249,6 +249,95 @@ static std::string trim_s(const std::string& s) {
return s.substr(a, b - a + 1);
}
// ---------------------------------------------------------------- breakpoint
// handlers
const char* bp_kind_name(BpKind kind) {
switch (kind) {
case BpKind::Conditional: return "conditional";
case BpKind::Logpoint: return "logpoint";
case BpKind::Plain: break;
}
return "plain";
}
bool bp_kind_from_name(const std::string& name, BpKind& kind) {
if (name == "plain") kind = BpKind::Plain;
else if (name == "conditional" || name == "cond")
kind = BpKind::Conditional;
else if (name == "logpoint" || name == "log" || name == "dprintf")
kind = BpKind::Logpoint;
else
return false;
return true;
}
// Quote one argument as an MI C-string: "s" with \ and " escaped.
static std::string mi_quote(const std::string& s) {
std::string out = "\"";
for (char c : s) {
if (c == '\\' || c == '"') out += '\\';
out += c;
}
out += '"';
return out;
}
bool logpoint_to_printf(const std::string& tmpl, std::string& fmt,
std::vector<std::string>& args) {
fmt.clear();
args.clear();
for (size_t i = 0; i < tmpl.size();) {
char c = tmpl[i];
if (c == '%') {
fmt += "%%"; // literal % must not become a format directive
++i;
continue;
}
if (c != '{') {
fmt += c;
++i;
continue;
}
size_t close = tmpl.find('}', i + 1);
if (close == std::string::npos) return false; // unbalanced {
std::string inner = tmpl.substr(i + 1, close - i - 1);
if (trim_s(inner).empty()) return false; // empty {}
// Optional one-letter format prefix before the first colon:
// {s:name} -> %s. Anything else (including a:b ternaries and
// a::b qualified names) is the whole expression, printed %d.
std::string spec = "%d";
std::string expr = inner;
size_t colon = inner.find(':');
if (colon == 1) {
const char* m = nullptr;
switch (inner[0]) {
case 'd': m = "%d"; break;
case 's': m = "%s"; break;
case 'f': m = "%f"; break;
case 'x': m = "%#x"; break;
case 'p': m = "%p"; break;
default: break;
}
if (m) {
spec = m;
expr = inner.substr(2);
}
}
expr = trim_s(expr);
if (expr.empty()) return false;
fmt += spec;
args.push_back(expr);
i = close + 1;
}
// dprintf output without a trailing newline would run into gdb's own
// console output; terminate the message (fmt holds a literal \n as
// backslash+n, which gdb's console parser turns into a newline).
if (fmt.size() < 2 || fmt.compare(fmt.size() - 2, 2, "\\n") != 0)
fmt += "\\n";
return true;
}
bool DebuggerSettings::save(const std::string& path) const {
std::string p = path.empty() ? default_path() : path;
ensure_parent_dir(p);
@@ -364,7 +453,7 @@ void GdbSession::shutdown() {
if (gdb_pid_ > 0) {
if (gdb_stdin_ >= 0) {
std::string bye = "-gdb-exit\n";
::write(gdb_stdin_, bye.data(), bye.size());
(void)::write(gdb_stdin_, bye.data(), bye.size());
}
// Give gdb a moment, then SIGKILL the group if it lingers.
for (int i = 0; i < 10; ++i) {
@@ -624,16 +713,15 @@ bool GdbSession::start(const std::string& executable, const std::string& args,
MiValue r;
if (!command("-exec-arguments " + args, r, err)) return false;
}
// Re-apply saved breakpoints (restart keeps them).
// Re-apply saved breakpoints (restart keeps them), with their full
// handler options (conditional / logpoint / ignore count / group).
std::vector<Breakpoint> old = bps_;
bps_.clear();
for (auto& b : old) {
Breakpoint nb;
std::string e;
if (add_breakpoint(b.location, nb, e)) {
nb.enabled = b.enabled;
if (!b.enabled) enable_breakpoint(nb.id, false, e);
}
add_breakpoint_opts(b.location, b, nb, e); // best effort: a stale
// location must not abort the run
}
if (settings_.break_on_main || settings_.stop_on_entry) {
Breakpoint bp;
@@ -741,23 +829,65 @@ bool GdbSession::wait_for_stop(int timeout_ms) {
// ---------------------------------------------------------------- breakpoints
bool GdbSession::stage_breakpoint(const std::string& location) {
return stage_breakpoint_opts(location, Breakpoint());
}
bool GdbSession::stage_breakpoint_opts(const std::string& location,
const Breakpoint& opts) {
std::string file;
int line = 0;
std::string func;
if (!parse_breakpoint_location(location, file, line, func)) return false;
for (const auto& b : bps_)
if (b.location == location) return true;
Breakpoint b;
Breakpoint b = opts;
b.location = location;
b.file = file;
b.line = line;
b.function = func;
b.id = 0; // not in gdb yet
// A condition without an explicit kind is a conditional breakpoint.
if (b.kind == BpKind::Plain && !b.condition.empty())
b.kind = BpKind::Conditional;
for (auto& old : bps_) {
if (old.location != location) continue;
if (old.id == 0) {
old = b; // re-stage: replace the staged entry's options
return true;
}
return true; // live breakpoint at this location: leave it alone
}
bps_.push_back(b);
return true;
}
bool GdbSession::add_breakpoint(const std::string& location, Breakpoint& out,
std::string& err) {
return add_breakpoint_opts(location, Breakpoint(), out, err);
}
// Apply condition (-break-condition) and ignore count (-break-after) to a
// breakpoint that already exists in gdb. The condition is MI-quoted, so
// expressions with spaces or string literals survive the trip.
bool GdbSession::apply_bp_options(int id, const Breakpoint& opts,
std::string& err) {
MiValue r;
if (!opts.condition.empty()) {
if (!command("-break-condition " + std::to_string(id) + " " +
mi_quote(opts.condition),
r, err))
return false;
}
if (opts.ignore_count > 0) {
if (!command("-break-after " + std::to_string(id) + " " +
std::to_string(opts.ignore_count),
r, err))
return false;
}
return true;
}
bool GdbSession::add_breakpoint_opts(const std::string& location,
const Breakpoint& opts, Breakpoint& out,
std::string& err) {
std::string file;
int line = 0;
std::string func;
@@ -766,12 +896,82 @@ bool GdbSession::add_breakpoint(const std::string& location, Breakpoint& out,
location;
return false;
}
MiValue r;
if (!command("-break-insert " + location, r, err)) return false;
const MiValue* bk = r.get("bkpt");
Breakpoint want = opts;
want.location = location;
if (want.kind == BpKind::Plain && !want.condition.empty())
want.kind = BpKind::Conditional;
if (want.kind == BpKind::Conditional &&
trim_s(want.condition).empty()) {
err = "conditional breakpoint needs a condition";
return false;
}
if (want.kind == BpKind::Logpoint && trim_s(want.log_message).empty()) {
err = "logpoint needs a log message";
return false;
}
if (want.ignore_count < 0) want.ignore_count = 0;
Breakpoint b;
b.location = location;
b.enabled = true;
if (want.kind == BpKind::Logpoint) {
// Logpoint = gdb dprintf: prints and never stops. There is no MI
// -break-insert flag for it, so create it through the console
// interpreter: dprintf LOC,"FMT", arg, ... The whole console
// command is one MI-quoted string; mi_quote escapes the quotes
// and backslashes inside it, and the \n in the format survives
// as a gdb string escape. The ^done reply carries no breakpoint
// number, so find the new dprintf entry with a re-list.
std::string fmt;
std::vector<std::string> args;
if (!logpoint_to_printf(want.log_message, fmt, args)) {
err = "bad log message template (unbalanced {braces} or empty "
"{}) : " +
want.log_message;
return false;
}
std::string console_cmd = "dprintf " + location + ",\"" + fmt + "\"";
for (const auto& a : args) console_cmd += ", " + a;
std::vector<int> before;
for (const auto& old : bps_) before.push_back(old.id);
MiValue r;
if (!command("-interpreter-exec console " + mi_quote(console_cmd),
r, err))
return false;
if (!refresh_breakpoints(err)) return false;
Breakpoint* found = nullptr;
for (auto& cand : bps_) {
if (cand.kind != BpKind::Logpoint) continue;
bool is_new = std::find(before.begin(), before.end(),
cand.id) == before.end();
if (is_new && (!found || cand.id > found->id)) found = &cand;
}
if (!found) {
err = "logpoint was created but gdb did not list it";
return false;
}
// Condition / ignore count also apply to dprintf breakpoints.
if (!apply_bp_options(found->id, want, err)) {
std::string e2;
remove_breakpoint(found->id, e2); // roll back
return false;
}
found->condition = want.condition;
found->ignore_count = want.ignore_count;
found->log_message = want.log_message;
found->group = want.group;
if (!want.enabled) {
std::string e2;
enable_breakpoint(found->id, false, e2);
found->enabled = false;
}
out = *found;
return true;
}
MiValue r;
if (!command("-break-insert " + location, r, err)) return false;
const MiValue* bk = r.get("bkpt");
if (bk) {
b.id = std::atoi(bk->get_str("number", "0").c_str());
b.file = bk->get_str("fullname");
@@ -795,17 +995,100 @@ bool GdbSession::add_breakpoint(const std::string& location, Breakpoint& out,
err = "gdb did not return a breakpoint number";
return false;
}
// Replace any existing entry with the same id/location.
b.kind = want.kind;
b.condition = want.condition;
b.ignore_count = want.ignore_count;
b.log_message = want.log_message;
b.group = want.group;
// Replace any existing entry with the same id.
for (auto& old : bps_)
if (old.id == b.id) old = b;
bool found = false;
for (auto& old : bps_)
if (old.id == b.id) found = true;
if (!found) bps_.push_back(b);
// gdb validates the condition here (unknown variable -> ^error);
// roll the breakpoint back so a bad condition leaves nothing behind.
if (!apply_bp_options(b.id, want, err)) {
std::string e2;
remove_breakpoint(b.id, e2);
return false;
}
if (!want.enabled) {
std::string e2;
enable_breakpoint(b.id, false, e2);
b.enabled = false;
for (auto& old : bps_)
if (old.id == b.id) old.enabled = false;
}
out = b;
return true;
}
bool GdbSession::update_breakpoint(int id, const Breakpoint& opts,
Breakpoint& out, std::string& err) {
Breakpoint* cur = nullptr;
for (auto& b : bps_)
if (b.id == id) {
cur = &b;
break;
}
if (!cur) {
// Staged entry (id 0): match by location and update in place.
for (auto& b : bps_)
if (b.id == 0 && b.location == opts.location) {
cur = &b;
break;
}
if (!cur) {
err = "no breakpoint with id " + std::to_string(id);
return false;
}
Breakpoint want = opts;
want.location = cur->location; // location is not editable here
want.id = 0;
want.file = cur->file;
want.line = cur->line;
want.function = cur->function;
want.hits = cur->hits;
if (want.kind == BpKind::Plain && !want.condition.empty())
want.kind = BpKind::Conditional;
*cur = want;
out = *cur;
return true;
}
if (!is_alive()) {
// gdb is down: keep the entry, options included, for start().
Breakpoint want = opts;
want.location = cur->location;
want.id = cur->id;
want.file = cur->file;
want.line = cur->line;
want.function = cur->function;
want.hits = cur->hits;
if (want.kind == BpKind::Plain && !want.condition.empty())
want.kind = BpKind::Conditional;
*cur = want;
out = *cur;
return true;
}
// Live: a kind change needs a new breakpoint (a plain breakpoint
// cannot become a dprintf in place), so delete + re-insert at the
// same location. The gdb id may change; `out` carries the new one.
std::string loc = cur->location;
Breakpoint want = opts;
want.location = loc;
std::string e;
if (!remove_breakpoint(id, e)) {
err = e;
return false;
}
Breakpoint nb;
if (!add_breakpoint_opts(loc, want, nb, err)) return false;
out = nb;
return true;
}
bool GdbSession::remove_breakpoint(int id, std::string& err) {
MiValue r;
if (!command("-break-delete " + std::to_string(id), r, err)) return false;
@@ -853,21 +1136,108 @@ bool GdbSession::refresh_breakpoints(std::string& err) {
: b.file + ":" + std::to_string(b.line);
}
b.hits = std::atoi(bk->get_str("times", "0").c_str());
// Handler fields straight from gdb: dprintf breakpoints
// report type="dprintf"; conditions and the remaining
// ignore count come back as cond=/ignore=. (gdb drops
// `ignore` once the count is spent, so a missing field
// means 0 remaining. The log template itself is not
// reported — it is merged back from our own record below.)
std::string type = bk->get_str("type");
b.condition = bk->get_str("cond");
b.ignore_count =
std::atoi(bk->get_str("ignore", "0").c_str());
if (type == "dprintf") b.kind = BpKind::Logpoint;
else if (!b.condition.empty()) b.kind = BpKind::Conditional;
fresh.push_back(b);
}
}
}
bps_ = fresh;
// Merge: gdb is authoritative for kind/condition/ignore/hits, but
// our own records keep the log template and group (gdb cannot
// report them). Staged entries (id 0, not in gdb yet) are kept.
std::vector<Breakpoint> merged;
for (auto& f : fresh) {
for (const auto& old : bps_) {
if (old.id != f.id) continue;
f.log_message = old.log_message;
f.group = old.group;
if (f.condition.empty()) f.condition = old.condition;
break;
}
merged.push_back(f);
}
for (const auto& old : bps_)
if (old.id == 0) merged.push_back(old);
bps_ = merged;
return true;
}
// Escape one persistence field: \ -> \\, | -> \|, newline -> \n, CR -> \r.
static std::string bps_escape(const std::string& s) {
std::string out;
for (char c : s) {
switch (c) {
case '\\': out += "\\\\"; break;
case '|': out += "\\|"; break;
case '\n': out += "\\n"; break;
case '\r': out += "\\r"; break;
default: out += c; break;
}
}
return out;
}
static std::string bps_unescape(const std::string& s) {
std::string out;
for (size_t i = 0; i < s.size(); ++i) {
if (s[i] == '\\' && i + 1 < s.size()) {
char c = s[++i];
switch (c) {
case 'n': out += '\n'; break;
case 'r': out += '\r'; break;
default: out += c; break; // \\ and \| (and anything else)
}
} else {
out += s[i];
}
}
return out;
}
// Split a persistence line on unescaped '|' (escapes stay in the parts
// for bps_unescape to handle).
static std::vector<std::string> bps_split(const std::string& line) {
std::vector<std::string> parts;
std::string cur;
for (size_t i = 0; i < line.size(); ++i) {
char c = line[i];
if (c == '\\' && i + 1 < line.size()) {
cur += c;
cur += line[++i];
continue;
}
if (c == '|') {
parts.push_back(cur);
cur.clear();
continue;
}
cur += c;
}
parts.push_back(cur);
return parts;
}
bool GdbSession::save_breakpoints(const std::string& path) const {
std::string p = path.empty() ? default_bps_path() : path;
ensure_parent_dir(p);
std::ofstream f(p);
if (!f) return false;
f << "# location|enabled|kind|condition|ignore|log_message|group\n";
for (const auto& b : bps_)
f << b.location << "|" << (b.enabled ? "1" : "0") << "\n";
f << bps_escape(b.location) << "|" << (b.enabled ? "1" : "0") << "|"
<< bp_kind_name(b.kind) << "|" << bps_escape(b.condition) << "|"
<< b.ignore_count << "|" << bps_escape(b.log_message) << "|"
<< bps_escape(b.group) << "\n";
return (bool)f;
}
@@ -880,11 +1250,22 @@ bool GdbSession::load_breakpoints(const std::string& path) {
while (std::getline(f, line)) {
std::string t = trim_s(line);
if (t.empty() || t[0] == '#') continue;
size_t bar = t.find('|');
std::vector<std::string> parts = bps_split(t);
Breakpoint b;
b.location = bar == std::string::npos ? t : t.substr(0, bar);
b.enabled = bar == std::string::npos ||
t.substr(bar + 1) != "0";
b.location = bps_unescape(parts[0]);
b.enabled = parts.size() < 2 || parts[1] != "0";
if (parts.size() >= 3 && !parts[2].empty()) {
BpKind k;
if (bp_kind_from_name(parts[2], k)) b.kind = k;
}
if (parts.size() >= 4) b.condition = bps_unescape(parts[3]);
if (parts.size() >= 5) b.ignore_count = std::atoi(parts[4].c_str());
if (parts.size() >= 6) b.log_message = bps_unescape(parts[5]);
if (parts.size() >= 7) b.group = bps_unescape(parts[6]);
// A condition without an explicit kind is a conditional
// breakpoint (also covers hand-edited files).
if (b.kind == BpKind::Plain && !b.condition.empty())
b.kind = BpKind::Conditional;
bps_.push_back(b);
}
return true;
@@ -998,3 +1379,4 @@ void GdbSession::refresh_on_stop() {
list_frames(frames_, err);
refresh_watches(err);
}
+63 -2
View File
@@ -9,10 +9,24 @@
// several locations (e.g. a one-line function body); the breakpoint id
// reported is the parent number.
//
// Breakpoint handlers: every breakpoint carries a kind — plain, conditional
// (stops only when a gdb expression is true, via -break-condition) or
// logpoint (a gdb dprintf: prints a message and never stops). Any kind may
// also carry an ignore count (first N hits are skipped, via -break-after;
// gdb counts every reach, ignored or not, in the breakpoint's `times`
// hit count) and a group label. A logpoint message is a template:
// literal text plus {expr} placeholders, printed as integers by default;
// {s:expr} prints a string, {f:expr} a float, {x:expr} hex, {p:expr} a
// pointer. A conditional breakpoint's `times` counts stops only — reaches
// where the condition is false are not hits at all.
//
// Settings live in ~/.config/fdesigner/debugger.conf (key=value, see
// DebuggerSettings::save/load). FDESIGNER_DEBUGGER_CONF overrides the
// path (used by tests). Breakpoints are persisted per session in
// ~/.config/fdesigner/debugger_bps.conf (location|enabled per line).
// ~/.config/fdesigner/debugger_bps.conf, one per line:
// location|enabled|kind|condition|ignore|log_message|group
// (\, | and newline inside fields are backslash-escaped.) Old two-field
// lines (location|enabled) still load as plain breakpoints.
#pragma once
#include <string>
@@ -34,6 +48,15 @@ struct DebuggerSettings {
bool load(const std::string& path = "");
};
// What a breakpoint does when its location is reached.
enum class BpKind { Plain, Conditional, Logpoint };
// Display name for a breakpoint kind ("plain"/"conditional"/"logpoint").
const char* bp_kind_name(BpKind kind);
// Parse a kind name; accepts "plain", "conditional"/"cond",
// "logpoint"/"log"/"dprintf". Returns false for anything else.
bool bp_kind_from_name(const std::string& name, BpKind& kind);
struct Breakpoint {
int id = 0; // gdb breakpoint number
std::string location; // as requested: "file:line" or "func"
@@ -41,7 +64,13 @@ struct Breakpoint {
int line = 0; // resolved line (0 if by function)
std::string function; // resolved function (may be empty)
bool enabled = true;
int hits = 0;
int hits = 0; // gdb `times`: reaches (conditional: stops)
// Multiple-handler fields (see the header comment above).
BpKind kind = BpKind::Plain;
std::string condition; // conditional: gdb expression, e.g. "i == 5"
int ignore_count = 0; // skip the first N hits (-break-after)
std::string log_message; // logpoint template, e.g. "i={i} sum={sum}"
std::string group; // optional group label (organisation only)
};
struct Variable {
@@ -91,6 +120,13 @@ std::string mi_unescape(const std::string& s);
// the text is not a plausible location (empty, no colon/function chars).
bool parse_breakpoint_location(const std::string& text, std::string& file,
int& line, std::string& function);
// Convert a logpoint message template ("reached loop, i={i} name={s:name}")
// to a gdb printf format string plus the argument expressions, in order.
// {expr} prints as %d; {s:expr} %s, {f:expr} %f, {x:expr} %#x, {p:expr} %p.
// Literal % in the template is escaped to %%. Returns false on an
// unbalanced brace or an empty placeholder. Exposed for tests.
bool logpoint_to_printf(const std::string& tmpl, std::string& fmt,
std::vector<std::string>& args);
class GdbSession {
public:
@@ -141,10 +177,30 @@ public:
// before Run); start() inserts it into gdb. Returns false if the
// location does not parse.
bool stage_breakpoint(const std::string& location);
// As above, with handler options (kind/condition/ignore/log/group).
// Replaces the options of an already-staged entry at the same
// location; a live breakpoint at the location is left alone.
bool stage_breakpoint_opts(const std::string& location,
const Breakpoint& opts);
bool add_breakpoint(const std::string& location, Breakpoint& out,
std::string& err);
// As above, with handler options. A conditional breakpoint needs a
// non-empty condition, a logpoint a non-empty message; gdb validates
// the condition expression (unknown variable -> error, and the
// breakpoint is rolled back). The breakpoint is created disabled
// when opts.enabled is false.
bool add_breakpoint_opts(const std::string& location,
const Breakpoint& opts, Breakpoint& out,
std::string& err);
bool remove_breakpoint(int id, std::string& err);
bool enable_breakpoint(int id, bool enable, std::string& err);
// Replace a breakpoint's handler options (location is unchanged).
// Live: delete + re-insert with the new options (the gdb id may
// change; `out` carries the new breakpoint). Staged (id 0, gdb not
// running): updated in place. Returns false + err when the id is
// unknown or gdb rejects the new options.
bool update_breakpoint(int id, const Breakpoint& opts, Breakpoint& out,
std::string& err);
bool refresh_breakpoints(std::string& err); // re-list from gdb
const std::vector<Breakpoint>& breakpoints() const { return bps_; }
// Breakpoints kept across sessions (saved to disk by the UI).
@@ -168,6 +224,8 @@ public:
void refresh_on_stop();
// Output accumulated so far (target stdout/stderr + gdb console text).
// Logpoint (dprintf) output arrives on gdb's console stream, so it
// lands in gdb_log(), not target_output().
const std::string& target_output() const { return target_output_; }
const std::string& gdb_log() const { return gdb_log_; }
void clear_output() { target_output_.clear(); gdb_log_.clear(); }
@@ -188,6 +246,9 @@ private:
// Send an -exec-* command; move to Running unless a fresh *stopped
// arrived while waiting for the ^running reply (see debugger.cpp).
bool issue_exec(const std::string& mi_cmd, std::string& err);
// Apply a breakpoint's condition (-break-condition) and ignore count
// (-break-after) to a breakpoint that already exists in gdb.
bool apply_bp_options(int id, const Breakpoint& opts, std::string& err);
DebuggerSettings settings_;
unsigned long stop_seq_ = 0; // incremented on every *stopped event
+275 -12
View File
@@ -2,7 +2,8 @@
// Layout (all built in code, no extra .ui file — the window is dynamic):
// toolbar: Run | Continue | Step Over | Step Into | Step Out | Stop | Restart | Settings
// target row: executable entry + Browse + args entry + status label
// middle: breakpoints list (id, location, enabled toggle, hits) |
// middle: breakpoints list (id, location, enabled toggle, hits, type,
// condition, ignore count, log message) |
// locals list (name, type, value) + watch entry/add + watch list
// stack frames list + current source line label
// bottom: target stdout/stderr text view
@@ -11,6 +12,7 @@
#include "debugger_ui.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
@@ -90,8 +92,16 @@ static void refresh_bp_list() {
if (!b.file.empty() && b.line > 0 &&
loc.find(b.file) == std::string::npos)
loc += " (" + b.file + ":" + std::to_string(b.line) + ")";
// Message column: the logpoint template, with the group appended
// when one is set (plain/conditional breakpoints show the group
// alone, so grouped breakpoints stay identifiable in the list).
std::string msg = b.log_message;
if (!b.group.empty())
msg += (msg.empty() ? "[" : " [") + b.group + "]";
gtk_list_store_set(g_bp_store, &it, 0, b.id, 1, loc.c_str(), 2,
b.enabled ? TRUE : FALSE, 3, b.hits, -1);
b.enabled ? TRUE : FALSE, 3, b.hits, 4,
bp_kind_name(b.kind), 5, b.condition.c_str(), 6,
b.ignore_count, 7, msg.c_str(), -1);
}
}
@@ -334,7 +344,234 @@ static void on_bp_remove_clicked(GtkButton*, gpointer) {
int id = 0;
gtk_tree_model_get(model, &it, 0, &id, -1);
std::string err;
if (!g_session->remove_breakpoint(id, err)) show_error(g_dbg_window, err);
if (id > 0) {
if (!g_session->remove_breakpoint(id, err))
show_error(g_dbg_window, err);
} else {
// Staged breakpoint (not in gdb yet): remove by list position —
// staged entries all share id 0, so the id alone cannot tell
// them apart.
GtkTreePath* tp = gtk_tree_model_get_path(model, &it);
int idx = tp ? gtk_tree_path_get_indices(tp)[0] : -1;
if (tp) gtk_tree_path_free(tp);
auto& bps = const_cast<std::vector<Breakpoint>&>(
g_session->breakpoints());
if (idx >= 0 && idx < (int)bps.size()) bps.erase(bps.begin() + idx);
}
g_session->save_breakpoints();
sync_ui_from_session();
}
// --- breakpoint add/edit dialog -----------------------------------------
//
// One dialog for the full handler set: kind (plain / conditional /
// logpoint), condition, ignore count, log message, group. For a new
// breakpoint the location is editable; for an existing one it is shown
// read-only (the backend's update keeps the location — delete the
// breakpoint and add a new one to move it).
static void bp_dialog_set_sensitive(GtkComboBox* kind_combo,
GtkWidget* cond_entry,
GtkWidget* log_entry) {
int active = gtk_combo_box_get_active(kind_combo);
gtk_widget_set_sensitive(cond_entry, active == 1);
gtk_widget_set_sensitive(log_entry, active == 2);
}
static void on_bp_kind_changed(GtkComboBox* combo, gpointer data) {
GtkWidget** widgets = (GtkWidget**)data; // [cond_entry, log_entry]
bp_dialog_set_sensitive(combo, widgets[0], widgets[1]);
}
// Edit `bp` in place; returns false when the user cancelled or the
// values do not validate (an error is shown in that case).
static bool breakpoint_edit_dialog(GtkWidget* parent, const char* title,
Breakpoint& bp, bool is_new) {
GtkWidget* d = gtk_dialog_new_with_buttons(
title, GTK_WINDOW(parent), GTK_DIALOG_MODAL, "_Cancel",
GTK_RESPONSE_CANCEL, "_Save", GTK_RESPONSE_ACCEPT, nullptr);
GtkWidget* content = gtk_dialog_get_content_area(GTK_DIALOG(d));
GtkWidget* grid = gtk_grid_new();
gtk_grid_set_row_spacing(GTK_GRID(grid), 6);
gtk_grid_set_column_spacing(GTK_GRID(grid), 8);
gtk_container_set_border_width(GTK_CONTAINER(grid), 10);
gtk_container_add(GTK_CONTAINER(content), grid);
GtkWidget* loc_entry = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(loc_entry), bp.location.c_str());
gtk_widget_set_hexpand(loc_entry, TRUE);
gtk_widget_set_sensitive(loc_entry, is_new);
gtk_grid_attach(GTK_GRID(grid), gtk_label_new("Location:"), 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), loc_entry, 1, 0, 1, 1);
GtkWidget* kind_combo = gtk_combo_box_text_new();
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(kind_combo), "Plain");
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(kind_combo),
"Conditional");
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(kind_combo),
"Logpoint");
gtk_combo_box_set_active(GTK_COMBO_BOX(kind_combo),
bp.kind == BpKind::Conditional
? 1
: (bp.kind == BpKind::Logpoint ? 2 : 0));
gtk_grid_attach(GTK_GRID(grid), gtk_label_new("Type:"), 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid), kind_combo, 1, 1, 1, 1);
GtkWidget* cond_entry = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(cond_entry), bp.condition.c_str());
gtk_entry_set_placeholder_text(
GTK_ENTRY(cond_entry), "e.g. i == 5 (only for Conditional)");
gtk_widget_set_hexpand(cond_entry, TRUE);
gtk_grid_attach(GTK_GRID(grid), gtk_label_new("Condition:"), 0, 2, 1, 1);
gtk_grid_attach(GTK_GRID(grid), cond_entry, 1, 2, 1, 1);
GtkWidget* ignore_spin = gtk_spin_button_new_with_range(0, 1000000, 1);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(ignore_spin),
bp.ignore_count);
gtk_grid_attach(GTK_GRID(grid),
gtk_label_new("Ignore first N hits:"), 0, 3, 1, 1);
gtk_grid_attach(GTK_GRID(grid), ignore_spin, 1, 3, 1, 1);
GtkWidget* log_entry = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(log_entry), bp.log_message.c_str());
gtk_entry_set_placeholder_text(
GTK_ENTRY(log_entry), "e.g. i={i} sum={sum} (only for Logpoint)");
gtk_widget_set_hexpand(log_entry, TRUE);
gtk_grid_attach(GTK_GRID(grid), gtk_label_new("Log message:"), 0, 4, 1, 1);
gtk_grid_attach(GTK_GRID(grid), log_entry, 1, 4, 1, 1);
GtkWidget* group_entry = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(group_entry), bp.group.c_str());
gtk_entry_set_placeholder_text(GTK_ENTRY(group_entry),
"optional group label");
gtk_widget_set_hexpand(group_entry, TRUE);
gtk_grid_attach(GTK_GRID(grid), gtk_label_new("Group:"), 0, 5, 1, 1);
gtk_grid_attach(GTK_GRID(grid), group_entry, 1, 5, 1, 1);
GtkWidget* hint = gtk_label_new(
"Conditional: stops only when the condition is true.\n"
"Logpoint: prints the message (never stops) — {expr} prints as an\n"
"integer, {s:name} as a string, {f:x} as a float, {x:v} as hex.\n"
"Ignore: the first N hits are skipped, then it stops as normal.\n"
"Logpoint output appears in the target-output pane as [gdb] text.");
gtk_label_set_xalign(GTK_LABEL(hint), 0.0);
gtk_grid_attach(GTK_GRID(grid), hint, 0, 6, 2, 1);
GtkWidget* sens_widgets[2] = {cond_entry, log_entry};
g_signal_connect(kind_combo, "changed", G_CALLBACK(on_bp_kind_changed),
sens_widgets);
bp_dialog_set_sensitive(GTK_COMBO_BOX(kind_combo), cond_entry, log_entry);
gtk_widget_show_all(d);
if (gtk_dialog_run(GTK_DIALOG(d)) != GTK_RESPONSE_ACCEPT) {
gtk_widget_destroy(d);
return false; // cancelled
}
std::string loc = entry_text(loc_entry);
int kind_active = gtk_combo_box_get_active(GTK_COMBO_BOX(kind_combo));
std::string cond = entry_text(cond_entry);
int ignore = gtk_spin_button_get_value_as_int(
GTK_SPIN_BUTTON(ignore_spin));
std::string logmsg = entry_text(log_entry);
std::string group = entry_text(group_entry);
gtk_widget_destroy(d);
std::string file;
int line = 0;
std::string func;
if (!parse_breakpoint_location(loc, file, line, func)) {
show_error(parent,
"not a breakpoint location (need file:line or "
"function): " +
loc);
return false;
}
if (kind_active == 1 && cond.empty()) {
show_error(parent,
"a conditional breakpoint needs a condition "
"(e.g. i == 5).");
return false;
}
if (kind_active == 2 && logmsg.empty()) {
show_error(parent,
"a logpoint needs a log message (e.g. i={i}).");
return false;
}
bp.location = loc;
bp.file = file;
bp.line = line;
bp.function = func;
bp.kind = kind_active == 1
? BpKind::Conditional
: (kind_active == 2 ? BpKind::Logpoint : BpKind::Plain);
bp.condition = cond;
bp.ignore_count = ignore;
bp.log_message = logmsg;
bp.group = group;
return true;
}
static void on_bp_add_full_clicked(GtkButton*, gpointer) {
std::string err;
if (!ensure_session(err)) return;
Breakpoint bp;
bp.location = entry_text(g_bp_entry);
if (!breakpoint_edit_dialog(g_dbg_window, "Add Breakpoint", bp, true))
return;
if (!g_session->is_alive()) {
if (!g_session->stage_breakpoint_opts(bp.location, bp)) {
show_error(g_dbg_window,
"not a breakpoint location (need file:line or "
"function): " +
bp.location);
return;
}
} else {
Breakpoint out;
if (!g_session->add_breakpoint_opts(bp.location, bp, out, err)) {
show_error(g_dbg_window, err);
return;
}
}
g_session->save_breakpoints();
gtk_entry_set_text(GTK_ENTRY(g_bp_entry), "");
sync_ui_from_session();
}
static void on_bp_edit_clicked(GtkButton*, gpointer) {
if (!g_session) return;
GtkTreeSelection* sel = gtk_tree_view_get_selection(
GTK_TREE_VIEW(g_object_get_data(G_OBJECT(g_dbg_window), "bp_view")));
GtkTreeModel* model = nullptr;
GtkTreeIter it;
if (!gtk_tree_selection_get_selected(sel, &model, &it)) return;
int id = 0;
gtk_tree_model_get(model, &it, 0, &id, -1);
// Find the breakpoint: by gdb id when live, by list position when
// staged (staged entries all share id 0).
Breakpoint* target = nullptr;
auto& bps = const_cast<std::vector<Breakpoint>&>(
g_session->breakpoints());
if (id > 0) {
for (auto& b : bps)
if (b.id == id) target = &b;
} else {
GtkTreePath* tp = gtk_tree_model_get_path(model, &it);
int idx = tp ? gtk_tree_path_get_indices(tp)[0] : -1;
if (tp) gtk_tree_path_free(tp);
if (idx >= 0 && idx < (int)bps.size()) target = &bps[idx];
}
if (!target) return;
Breakpoint edited = *target;
if (!breakpoint_edit_dialog(g_dbg_window, "Edit Breakpoint", edited,
false))
return;
std::string err;
Breakpoint out;
if (!g_session->update_breakpoint(target->id, edited, out, err)) {
show_error(g_dbg_window, err);
return;
}
g_session->save_breakpoints();
sync_ui_from_session();
}
@@ -350,15 +587,23 @@ static void on_bp_toggled(GtkCellRendererToggle*, gchar* path, gpointer) {
gtk_tree_model_get(GTK_TREE_MODEL(g_bp_store), &it, 0, &id, 2, &enabled,
-1);
std::string err;
if (g_session->is_alive()) {
if (g_session->is_alive() && id > 0) {
if (!g_session->enable_breakpoint(id, !enabled, err)) {
show_error(g_dbg_window, err);
return;
}
} else {
for (auto& b : const_cast<std::vector<Breakpoint>&>(
g_session->breakpoints()))
if (b.id == id) b.enabled = !enabled;
// gdb down, or a staged breakpoint (id 0): toggle by list
// position — staged entries all share id 0, so the id alone
// cannot tell them apart.
int idx = std::atoi(path);
auto& bps = const_cast<std::vector<Breakpoint>&>(
g_session->breakpoints());
if (idx >= 0 && idx < (int)bps.size())
bps[idx].enabled = !enabled;
else if (id > 0)
for (auto& b : bps)
if (b.id == id) b.enabled = !enabled;
}
g_session->save_breakpoints();
sync_ui_from_session();
@@ -612,21 +857,39 @@ void debugger_window_open(GtkWidget* parent) {
g_signal_connect(add, "clicked", G_CALLBACK(on_bp_add_clicked),
nullptr);
gtk_box_pack_start(GTK_BOX(row), add, FALSE, FALSE, 0);
GtkWidget* add_full = gtk_button_new_with_label("Add…");
gtk_widget_set_tooltip_text(
add_full, "Add a breakpoint with handler options: conditional, "
"ignore count, logpoint, group");
g_signal_connect(add_full, "clicked",
G_CALLBACK(on_bp_add_full_clicked), nullptr);
gtk_box_pack_start(GTK_BOX(row), add_full, FALSE, FALSE, 0);
GtkWidget* edit = gtk_button_new_with_label("Edit…");
gtk_widget_set_tooltip_text(
edit, "Edit the selected breakpoint's type, condition, "
"ignore count, log message or group");
g_signal_connect(edit, "clicked", G_CALLBACK(on_bp_edit_clicked),
nullptr);
gtk_box_pack_start(GTK_BOX(row), edit, FALSE, FALSE, 0);
GtkWidget* del = gtk_button_new_with_label("Remove");
g_signal_connect(del, "clicked", G_CALLBACK(on_bp_remove_clicked),
nullptr);
gtk_box_pack_start(GTK_BOX(row), del, FALSE, FALSE, 0);
g_bp_store = gtk_list_store_new(4, G_TYPE_INT, G_TYPE_STRING,
G_TYPE_BOOLEAN, G_TYPE_INT);
const char* cols[] = {"#", "Location", "Enabled", "Hits"};
GtkWidget* view = make_tree_view(g_bp_store, cols, 4, true);
g_bp_store = gtk_list_store_new(
8, G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
const char* cols[] = {"#", "Location", "Enabled", "Hits",
"Type", "Condition", "Ignore", "Message"};
GtkWidget* view = make_tree_view(g_bp_store, cols, 8, true);
g_object_set_data(G_OBJECT(win), "bp_view", view);
GtkWidget* sc = gtk_scrolled_window_new(nullptr, nullptr);
gtk_container_add(GTK_CONTAINER(sc), view);
gtk_box_pack_start(GTK_BOX(box), sc, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box),
gtk_label_new("Breakpoints (toggle Enabled to "
"enable/disable)"),
"enable/disable; Add… / Edit… for "
"conditional, ignore-count and "
"logpoint handlers)"),
FALSE, FALSE, 0);
}
+236
View File
@@ -515,6 +515,202 @@ static void console_tests() {
sess2.breakpoints()[1].location == "compute";
report("bps_persist_to_disk", ok, "");
}
// 31. conditional breakpoint: fires only when i == 2, never before
{
GdbSession sess;
std::string err;
Breakpoint opts;
opts.kind = BpKind::Conditional;
opts.condition = "i == 2";
bool ok = sess.stage_breakpoint_opts(loc(src, L_LOOP), opts);
ok = ok && sess.start(console, "", err);
ok = ok && sess.wait_for_stop();
ok = ok && sess.state() == DbgState::Stopped &&
sess.last_stop().reason == "breakpoint-hit" &&
sess.last_stop().frame.line == L_LOOP;
std::string v, e;
ok = ok && sess.evaluate("i", v, e) && v == "2";
// It must NOT have stopped at i=0/1: both iterations printed
// before the first (and only) stop.
ok = ok && sess.target_output().find("i=0 x=1 sum=1") !=
std::string::npos &&
sess.target_output().find("i=1 x=3 sum=4") != std::string::npos;
// Hit count from gdb: a conditional breakpoint counts stops
// only (reaches with a false condition are not hits) -> 1.
ok = ok && sess.refresh_breakpoints(err);
int hits = -1;
for (const auto& b : sess.breakpoints())
if (b.line == L_LOOP) hits = b.hits;
ok = ok && hits == 1;
ok = ok && sess.cont(err) && sess.wait_for_stop();
ok = ok && sess.state() == DbgState::Exited;
report("bp_conditional_only_when_true", ok,
"i=" + v + " hits=" + std::to_string(hits));
}
// 32. ignore count: first 2 hits skipped, stops on the 3rd (i == 2)
{
GdbSession sess;
std::string err;
Breakpoint opts;
opts.ignore_count = 2;
bool ok = sess.stage_breakpoint_opts(loc(src, L_LOOP), opts);
ok = ok && sess.start(console, "", err);
ok = ok && sess.wait_for_stop();
ok = ok && sess.state() == DbgState::Stopped &&
sess.last_stop().frame.line == L_LOOP;
std::string v, e;
ok = ok && sess.evaluate("i", v, e) && v == "2";
ok = ok && sess.target_output().find("i=0 x=1 sum=1") !=
std::string::npos &&
sess.target_output().find("i=1 x=3 sum=4") != std::string::npos;
// gdb counts every reach, ignored or not, in `times` -> 3.
ok = ok && sess.refresh_breakpoints(err);
int hits = -1;
for (const auto& b : sess.breakpoints())
if (b.line == L_LOOP) hits = b.hits;
ok = ok && hits == 3;
ok = ok && sess.cont(err) && sess.wait_for_stop();
ok = ok && sess.state() == DbgState::Exited;
report("bp_ignore_count_skips", ok,
"i=" + v + " hits=" + std::to_string(hits));
}
// 33. logpoint: prints its message at every hit, never stops
{
GdbSession sess;
std::string err;
Breakpoint opts;
opts.kind = BpKind::Logpoint;
opts.log_message = "LOG i={i}";
bool ok = sess.stage_breakpoint_opts(loc(src, L_LOOP), opts);
ok = ok && sess.start(console, "", err);
ok = ok && sess.wait_for_stop(10000);
// No stop at all: straight to a clean exit.
ok = ok && sess.state() == DbgState::Exited &&
sess.exit_code() == 0;
// dprintf output arrives on gdb's console stream (-> gdb_log()).
ok = ok && sess.gdb_log().find("LOG i=0") != std::string::npos &&
sess.gdb_log().find("LOG i=1") != std::string::npos &&
sess.gdb_log().find("LOG i=2") != std::string::npos;
ok = ok && sess.target_output().find("DONE sum=9") !=
std::string::npos;
report("bp_logpoint_prints_no_stop", ok, sess.gdb_log());
}
// 34. logpoint template with several placeholders and formats
{
// Template conversion is pure string work: check it directly.
std::string fmt;
std::vector<std::string> args;
bool ok = logpoint_to_printf("i={i} s={s:name} x={x:v}", fmt, args);
ok = ok && fmt == "i=%d s=%s x=%#x\\n" && args.size() == 3 &&
args[0] == "i" && args[1] == "name" && args[2] == "v";
ok = ok && logpoint_to_printf("100% done", fmt, args) &&
fmt == "100%% done\\n" && args.empty();
ok = ok && !logpoint_to_printf("oops {i", fmt, args);
ok = ok && !logpoint_to_printf("oops {}", fmt, args);
// And end to end: two placeholders print at the loop.
GdbSession sess;
std::string err;
Breakpoint opts;
opts.kind = BpKind::Logpoint;
opts.log_message = "LP i={i} sum={sum}";
ok = ok && sess.stage_breakpoint_opts(loc(src, L_LOOP), opts);
ok = ok && sess.start(console, "", err);
ok = ok && sess.wait_for_stop(10000);
ok = ok && sess.state() == DbgState::Exited;
ok = ok && sess.gdb_log().find("LP i=0 sum=0") != std::string::npos &&
sess.gdb_log().find("LP i=2 sum=4") != std::string::npos;
report("bp_logpoint_template", ok, sess.gdb_log());
}
// 35. edit a live breakpoint: plain -> conditional, takes effect
{
GdbSession sess;
std::string err;
sess.stage_breakpoint(loc(src, L_LOOP));
bool ok = sess.start(console, "", err);
ok = ok && sess.wait_for_stop();
ok = ok && sess.state() == DbgState::Stopped;
std::string v, e;
ok = ok && sess.evaluate("i", v, e) && v == "0"; // plain: stops at 0
int loop_id = 0;
for (const auto& b : sess.breakpoints())
if (b.line == L_LOOP) loop_id = b.id;
ok = ok && loop_id > 0;
Breakpoint upd;
upd.kind = BpKind::Conditional;
upd.condition = "i == 2";
upd.location = loc(src, L_LOOP);
Breakpoint out;
ok = ok && sess.update_breakpoint(loop_id, upd, out, err);
ok = ok && out.kind == BpKind::Conditional &&
out.condition == "i == 2";
ok = ok && sess.cont(err) && sess.wait_for_stop();
ok = ok && sess.state() == DbgState::Stopped &&
sess.last_stop().frame.line == L_LOOP;
ok = ok && sess.evaluate("i", v, e) && v == "2";
ok = ok && sess.cont(err) && sess.wait_for_stop();
ok = ok && sess.state() == DbgState::Exited;
report("bp_update_plain_to_conditional", ok, "i=" + v);
}
// 36. handler fields persist to disk and load back; old two-field
// files still load as plain breakpoints.
{
GdbSession sess;
Breakpoint c;
c.kind = BpKind::Conditional;
c.condition = "i == 2 || sum > 3"; // exercises | escaping
c.group = "loop";
Breakpoint l;
l.kind = BpKind::Logpoint;
l.log_message = "LOG i={i} | sum={sum}";
l.group = "trace";
Breakpoint p;
p.ignore_count = 3;
bool ok = sess.stage_breakpoint_opts(loc(src, L_LOOP), c);
ok = ok && sess.stage_breakpoint_opts(loc(src, L_HELPER), l);
ok = ok && sess.stage_breakpoint_opts("compute", p);
ok = ok && sess.save_breakpoints("/tmp/dbgtest_bps2");
GdbSession sess2;
ok = ok && sess2.load_breakpoints("/tmp/dbgtest_bps2");
ok = ok && sess2.breakpoints().size() == 3;
if (ok) {
const auto& b0 = sess2.breakpoints()[0];
const auto& b1 = sess2.breakpoints()[1];
const auto& b2 = sess2.breakpoints()[2];
ok = b0.kind == BpKind::Conditional &&
b0.condition == "i == 2 || sum > 3" && b0.group == "loop" &&
b1.kind == BpKind::Logpoint &&
b1.log_message == "LOG i={i} | sum={sum}" &&
b1.group == "trace" && b2.kind == BpKind::Plain &&
b2.ignore_count == 3 && b2.location == "compute";
}
// Old format: location|enabled, nothing else.
{
std::ofstream f("/tmp/dbgtest_bps_old");
f << loc(src, L_LOOP) << "|1\ncompute|0\n";
}
GdbSession sess3;
ok = ok && sess3.load_breakpoints("/tmp/dbgtest_bps_old");
ok = ok && sess3.breakpoints().size() == 2 &&
sess3.breakpoints()[0].kind == BpKind::Plain &&
sess3.breakpoints()[0].enabled &&
sess3.breakpoints()[1].kind == BpKind::Plain &&
!sess3.breakpoints()[1].enabled;
// A bad condition is rejected and leaves no breakpoint behind.
{
GdbSession s4;
std::string e2;
s4.start_gdb_only(e2);
s4.load_executable(console, e2);
Breakpoint bad;
bad.kind = BpKind::Conditional;
bad.condition = "nosuchvar == 2";
Breakpoint out;
ok = ok && !s4.add_breakpoint_opts(loc(src, L_LOOP), bad, out,
e2) &&
!e2.empty() && s4.breakpoints().empty();
}
report("bp_handlers_persist_roundtrip", ok, "");
}
}
// ---- GTK tests (run under xvfb-run) ---------------------------------------
@@ -577,6 +773,46 @@ static void gtk_tests() {
ok = ok && sess.target_output().find("CLICKS=1") != std::string::npos;
report("gtk_run_to_completion", ok, sess.target_output());
}
// 35. logpoint in the callback: prints, never stops, app exits 0
{
GdbSession sess;
std::string err;
Breakpoint opts;
opts.kind = BpKind::Logpoint;
opts.log_message = "CLICK counter={counter}";
bool ok = sess.stage_breakpoint_opts(loc(src, L_CB), opts);
ok = ok && sess.start(app, "", err);
ok = ok && sess.wait_for_stop(15000);
ok = ok && sess.state() == DbgState::Exited && sess.exit_code() == 0;
ok = ok && sess.target_output().find("CLICKS=1") !=
std::string::npos;
// At the callback entry counter is still 0 (the click has not
// been counted yet); the dprintf output is on gdb's console
// stream (-> gdb_log()).
ok = ok && sess.gdb_log().find("CLICK counter=0") !=
std::string::npos;
report("gtk_logpoint_no_stop", ok, sess.gdb_log());
}
// 36. conditional breakpoint in the callback: fires when counter == 0
{
GdbSession sess;
std::string err;
Breakpoint opts;
opts.kind = BpKind::Conditional;
opts.condition = "counter == 0";
bool ok = sess.stage_breakpoint_opts(loc(src, L_CB), opts);
ok = ok && sess.start(app, "", err);
ok = ok && sess.wait_for_stop(15000);
ok = ok && sess.state() == DbgState::Stopped &&
sess.last_stop().reason == "breakpoint-hit" &&
sess.last_stop().frame.line == L_CB;
ok = ok && sess.cont(err) && sess.wait_for_stop(15000);
ok = ok && sess.state() == DbgState::Exited && sess.exit_code() == 0;
ok = ok && sess.target_output().find("CLICKS=1") !=
std::string::npos;
report("gtk_conditional_in_callback", ok,
"reason=" + sess.last_stop().reason);
}
}
int main(int argc, char** argv) {