Skip to content

Commit

Permalink
Add -break-watch command
Browse files Browse the repository at this point in the history
Set watches.  Format is:

-break-watch expression

Watch will be set on address that results from evaluating 'expression'.

Also needed to add processing of a watch stoppage to events.cpp
  • Loading branch information
scootdj committed Feb 27, 2018
1 parent e53606a commit bd72e67
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/engine.cpp
Expand Up @@ -572,6 +572,68 @@ fromCDT (STATE *pstate, const char *commandLine, int linesize) // from cdt
breakpoint.SetEnabled(0);
cdtprintf ("%d^done\n(gdb)\n", cc.sequence);
}
else if (strcmp(cc.argv[0],"-break-watch")==0) {
// -break-watch [-r|-a] expression
// Set a watch on address that results from evaluating 'expression'
char expression[LINE_MAX];
char watchExpr[LINE_MAX];
bool isRead = false;
bool isWrite = true;
if (strcmp(cc.argv[nextarg],"-a")==0) {
isRead = true;
nextarg++;
}
if (strcmp(cc.argv[nextarg],"-r")==0) {
isRead = true;
isWrite = false;
nextarg++;
}
if (nextarg<cc.argc)
strlcpy (expression, cc.argv[nextarg++], sizeof(expression));

/* Convert Pascal expression to C
* Expected formats from laz-ide are:
* type(addr_t^)
* ^type(addr_t^)
* In spite of '^' at end of addresses we want straight address not dereference
*/
char *typeStr = expression;
if (*typeStr == '^')
typeStr++;
char *addrStr = strchr(typeStr, '(');
if (addrStr != NULL) {
*addrStr++ = '\0';
char *tmp = strchr(addrStr,')');
if ((tmp != NULL) && (*(tmp-1) == '^')) {
tmp--;
*tmp = '\0';
}
}
snprintf(watchExpr, sizeof(watchExpr), "(%s *)(%s)", typeStr, addrStr);
/*
* End of Pascal manipulation
*/

SBValue val = target.EvaluateExpression(watchExpr);
if (val.IsValid()) {
addr_t watchAddr = val.GetValueAsUnsigned();
if (watchAddr != 0) {
SBError error;
SBWatchpoint watch = target.WatchAddress(watchAddr, val.GetByteSize(), isRead, isWrite, error);
if (watch.IsValid() && error.Success()) {
cdtprintf ("%d^done,wpt={number=\"%d\",\"%s\"}\n(gdb)\n", cc.sequence, watch.GetID(), watchExpr);
}
else
cdtprintf ("^error,msg=\"Could not create watch: %s\"\n(gdb) \n", error.GetCString());
}
else
cdtprintf ("^error,msg=\"Value failed to return valid address (%s %s %p)\"\n(gdb) \n", watchExpr, val.GetValue(), watchAddr);
}
else {
SBError err = val.GetError();
cdtprintf ("^error,msg=\"Expression does not return valid value: %s\"\n(gdb) \n", err.GetCString());
}
}
// STACK COMMANDS
else if (strcmp(cc.argv[0],"-list-thread-groups")==0) {
// list-thread-groups --available
Expand Down
27 changes: 27 additions & 0 deletions src/events.cpp
Expand Up @@ -159,6 +159,9 @@ processListener (void *arg)
break;
}
}
if (SBWatchpoint::EventIsWatchpointEvent(event)) {
printf("Is Watchpoint event\n");
}
else
logprintf (LOG_EVENTS, "event type %s\n", eventtype);
}
Expand Down Expand Up @@ -219,6 +222,30 @@ onStopped (STATE *pstate, SBProcess process)
cdtprintf ("=breakpoint-deleted,id=\"%d\"\n", bpid);
}
}
else if (stopreason==eStopReasonWatchpoint) {
if (thread.GetStopReasonDataCount() > 0) {
int wpid = thread.GetStopReasonDataAtIndex(0);
SBWatchpoint watch = target.FindWatchpointByID(wpid);
cdtprintf ("*stopped,reason=\"watchpoint-trigger\",wpt={number=\"%d\",exp=\"%p\"},",
watch.GetID(), watch.GetWatchAddress());
SBStream str;
watch.GetDescription(str,eDescriptionLevelVerbose);
const char *desc = str.GetData();
uint64_t oldValue=0, newValue=0;
const char *s = strstr(desc, "old value:");
sscanf(s, "%*[^0-9]%lli", &oldValue);
s = strstr(desc, "new value:");
sscanf(s, "%*[^0-9]%lli", &newValue);
cdtprintf ("value={old=\"%llu\",new=\"%llu\"},", oldValue, newValue);
SBFrame frame = thread.GetSelectedFrame();
SBLineEntry lentry = frame.GetLineEntry();
SBFileSpec fspec = lentry.GetFileSpec();
cdtprintf ("frame={func=\"%s\",args=[],file=\"%s\",line=\"%d\"}\n(gdb)\n",
frame.GetFunctionName(), fspec.GetFilename(), lentry.GetLine());
}
else
cdtprintf ("*stopped,reason=\"watchpoint-trigger\"}\n(gdb)\n");
}
else if (stopreason==eStopReasonSignal) {
// raised when attaching to a process
// raised when program crashed
Expand Down

0 comments on commit bd72e67

Please sign in to comment.