Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/44606 )
Change subject: base: Improve handling of thread IDs for remote GDB.
......................................................................
base: Improve handling of thread IDs for remote GDB.
The remote GDB protocol encode thread IDs as positive integers, where 0
is a special value which indicates "pick any thread", and -1 is a
special value which indicates all threads.
The previous implementation would look like it worked handling the
special value -1 (for instance) because it see the '-' of "-1", stop
looking for digits, and return the default value 0.
This new implementation handles -1 as a special case, and will report an
error if no digits were found otherwise.
Also this change adds an encodeThreadId method to convert a ContextID
into a GDB thread ID by adding one to avoid the special value 0.
Change-Id: Iec54fbd9563d20a56011f48d50d69111ed1467b8
---
M src/base/remote_gdb.cc
1 file changed, 44 insertions(+), 3 deletions(-)
diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc
index 9278eb0..3fc5240 100644
--- a/src/base/remote_gdb.cc
+++ b/src/base/remote_gdb.cc
@@ -283,6 +283,43 @@
return r;
}
+bool
+parseThreadId(const char **srcp, bool &all, bool &any, ContextID &tid)
+{
+ all = any = false;
+ tid = 0;
+ const char *src = *srcp;
+ if (*src == '-') {
+ // This could be the start of -1, which means all threads.
+ src++;
+ if (*src++ != '1')
+ return false;
+ *srcp += 2;
+ all = true;
+ return true;
+ }
+ tid = hex2i(srcp);
+ // If *srcp still points to src, no characters were consumed and no
thread
+ // id was found. Without this check, we can't tell the difference
between
+ // zero and a parsing error.
+ if (*srcp == src)
+ return false;
+
+ if (tid == 0)
+ any = true;
+
+ tid--;
+
+ return true;
+}
+
+int
+encodeThreadId(ContextID id)
+{
+ // Thread ID 0 is reserved and means "pick any thread".
+ return id + 1;
+}
+
enum GdbBreakpointType
{
GdbSoftBp = '0',
@@ -864,8 +901,12 @@
BaseRemoteGDB::cmdSetThread(GdbCommand::Context &ctx)
{
const char *p = ctx.data + 1; // Ignore the subcommand byte.
- if (hex2i(&p) != tc->contextId())
+ ContextID tid = 0;
+ bool all, any;
+ if (!parseThreadId(&p, all, any, tid))
throw CmdError("E01");
+ if (any || all || tid != tc->contextId())
+ throw CmdError("E02");
send("OK");
return true;
}
@@ -945,7 +986,7 @@
void
BaseRemoteGDB::queryC(QuerySetCommand::Context &ctx)
{
- send(csprintf("QC%x", tc->contextId()).c_str());
+ send(csprintf("QC%x", encodeThreadId(tc->contextId())).c_str());
}
void
@@ -1005,7 +1046,7 @@
void
BaseRemoteGDB::queryFThreadInfo(QuerySetCommand::Context &ctx)
{
- send(csprintf("m%x", tc->contextId()).c_str());
+ send(csprintf("m%x", encodeThreadId(tc->contextId())).c_str());
}
void
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/44606
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Iec54fbd9563d20a56011f48d50d69111ed1467b8
Gerrit-Change-Number: 44606
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s