-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement Jump to Line #1042
base: main
Are you sure you want to change the base?
implement Jump to Line #1042
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -157,7 +157,7 @@ public override async Task<Results> ThreadInfo(uint? threadId = null) | |||||
|
||||||
public override async Task<List<ulong>> StartAddressesForLine(string file, uint line) | ||||||
{ | ||||||
string cmd = "info line " + file + ":" + line; | ||||||
string cmd = "info line -s " + file + " -li " + line; | ||||||
var result = await _debugger.ConsoleCmdAsync(cmd, allowWhileRunning: false); | ||||||
List<ulong> addresses = new List<ulong>(); | ||||||
using (StringReader stringReader = new StringReader(result)) | ||||||
|
@@ -173,7 +173,7 @@ public override async Task<List<ulong>> StartAddressesForLine(string file, uint | |||||
{ | ||||||
ulong address; | ||||||
string addrStr = resultLine.Substring(pos + 18); | ||||||
if (MICommandFactory.SpanNextAddr(addrStr, out address) != null) | ||||||
if (SpanNextAddr(addrStr, out address) != null) | ||||||
{ | ||||||
addresses.Add(address); | ||||||
} | ||||||
|
@@ -183,6 +183,30 @@ public override async Task<List<ulong>> StartAddressesForLine(string file, uint | |||||
return addresses; | ||||||
} | ||||||
|
||||||
private async Task JumpInternal(string target) | ||||||
{ | ||||||
// temporary breakpoint + jump | ||||||
// NB: the gdb docs state: "Resume execution at line linespec. Execution stops again immediately if there is a breakpoint there." | ||||||
// We rely on this. If another thread hits a breakpoint before that we have a UX problem | ||||||
// and would need to handle this via scheduler-locking for all-stop mode and ??? for non-stop mode. | ||||||
await _debugger.CmdAsync("-break-insert -t " + target, ResultClass.done); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this temporary breakpoint not registered, when we get a stopping event it will be unknown and returned as an exception.
I think we need to treat this as an async break. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean by not registered? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On stopping and when it is a breakpoint, we go through a list of breakpoints:
If if there are none, we assume it is an entrypoint breakpoint, embedded, we hit a bp pending deletion, or it is an exception. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. It does receive a <-1067-break-insert -t *0x5555555573B1
->1067^done,bkpt={number="3",type="breakpoint",disp="del",enabled="y",addr="0x00005555555573b1",func="main(int, "...
<-1068-exec-jump *0x5555555573B1
->1068^running
->*running,thread-id="all"
->=breakpoint-modified,bkpt={number="3",type="breakpoint",disp="del",enabled="y",addr="0x00005555555573b1",func="main(int, "...
->*stopped,reason="breakpoint-hit",disp="del",bkptno="3",frame={addr="0x00005555555573b1",func="main",args=[{name="argc",value="1"},{name="argv",value="0x7fffffffdb68"}],file="../test.cpp",fullname="/tmp/test.cpp",line="28",arch="i386:x86-64"},thread-id="1",stopped-threads="all",core="6"
->=breakpoint-deleted,id="3"
|
||||||
await _debugger.CmdAsync("-exec-jump " + target, ResultClass.running); | ||||||
Trass3r marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
public override Task ExecJump(string filename, int line) | ||||||
{ | ||||||
string target = "--source " + filename + " --line " + line.ToString(CultureInfo.InvariantCulture); | ||||||
return JumpInternal(target); | ||||||
} | ||||||
|
||||||
public override Task ExecJump(ulong address) | ||||||
{ | ||||||
return _debugger.ConsoleCmdAsync("set $pc = " + string.Format(CultureInfo.InvariantCulture, "0x{0:X}", address), false); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The question is if some kind of error handling is needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally yes, but since this is a non-MI command, there aren't wonderful options for knowing it is succeeded. I am not sure if GDB supports assigning to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it but requires a variable object incl. creation/deletion (possibly just once): https://sourceware.org/gdb/current/onlinedocs/gdb/GDB_002fMI-Variable-Objects.html |
||||||
|
||||||
string target = "*" + string.Format(CultureInfo.InvariantCulture, "0x{0:X}", address); | ||||||
return JumpInternal(target); | ||||||
} | ||||||
|
||||||
public override Task EnableTargetAsyncOption() | ||||||
{ | ||||||
// Linux attach TODO: GDB will fail this command when attaching. This is worked around | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,6 +182,45 @@ public object GetMetric(string metric) | |
return _configStore.GetEngineMetric(metric); | ||
} | ||
|
||
public int Jump(string filename, int line) | ||
{ | ||
try | ||
{ | ||
_debuggedProcess.WorkerThread.RunOperation(() => _debuggedProcess.Jump(filename, line)); | ||
} | ||
catch (InvalidCoreDumpOperationException) | ||
{ | ||
return AD7_HRESULT.E_CRASHDUMP_UNSUPPORTED; | ||
} | ||
catch (Exception e) | ||
{ | ||
_engineCallback.OnError(EngineUtils.GetExceptionDescription(e)); | ||
return Constants.E_ABORT; | ||
} | ||
|
||
return Constants.S_OK; | ||
} | ||
|
||
Trass3r marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public int Jump(ulong address) | ||
{ | ||
try | ||
{ | ||
_debuggedProcess.WorkerThread.RunOperation(() => _debuggedProcess.Jump(address)); | ||
} | ||
catch (InvalidCoreDumpOperationException) | ||
{ | ||
return AD7_HRESULT.E_CRASHDUMP_UNSUPPORTED; | ||
} | ||
catch (Exception e) | ||
{ | ||
_engineCallback.OnError(EngineUtils.GetExceptionDescription(e)); | ||
return Constants.E_ABORT; | ||
} | ||
DebuggedProcess.ThreadCache.MarkDirty(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was needed to update the current line in the UI. Is it the right place? |
||
|
||
return Constants.S_OK; | ||
} | ||
|
||
#region IDebugEngine2 Members | ||
|
||
// Attach the debug engine to a program. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1631,6 +1631,16 @@ public Task Continue(DebuggedThread thread) | |
return Execute(thread); | ||
} | ||
|
||
public async Task Jump(string filename, int line) | ||
{ | ||
await MICommandFactory.ExecJump(filename, line); | ||
} | ||
Trass3r marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to remove all the overloads that use filename and line number since we always seem to use the overload that take the address. |
||
|
||
public async Task Jump(ulong address) | ||
{ | ||
Trass3r marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await MICommandFactory.ExecJump(address); | ||
} | ||
|
||
public async Task Step(int threadId, enum_STEPKIND kind, enum_STEPUNIT unit) | ||
{ | ||
this.VerifyNotDebuggingCoreDump(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1337,7 +1337,37 @@ protected override void HandlePauseRequestAsync(IRequestResponder<PauseArguments | |
|
||
protected override void HandleGotoRequestAsync(IRequestResponder<GotoArguments> responder) | ||
{ | ||
responder.SetError(new ProtocolException(AD7Resources.Error_NotImplementedSetNextStatement)); | ||
var response = new GotoResponse(); | ||
Trass3r marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!m_isStopped) | ||
{ | ||
responder.SetResponse(response); | ||
return; | ||
} | ||
|
||
var builder = new ErrorBuilder(() => AD7Resources.Error_UnableToSetNextStatement); | ||
IDebugThread2 thread = null; | ||
try | ||
{ | ||
if (m_gotoCodeContexts.TryGetValue(responder.Arguments.TargetId, out IDebugCodeContext2 gotoTarget)) | ||
{ | ||
lock (m_threads) | ||
{ | ||
if (!m_threads.TryGetValue(responder.Arguments.ThreadId, out thread)) | ||
throw new AD7Exception("Unknown thread id: " + responder.Arguments.ThreadId.ToString(CultureInfo.InvariantCulture)); | ||
} | ||
//BeforeContinue(); | ||
builder.CheckHR(thread.SetNextStatement(null, gotoTarget)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok to remove? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably want BeforeContinue. The other debug adapter that the VS debugger team owns currently doesn't clear our handle collections on SetNextStatement, but you are probably correct that it should. But we should check VS Code and make sure it is happy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah idk technically it doesn't run the program but on the other hand the current line of code needs to be updated. The thread cache invalidation worked in VSCode. |
||
} | ||
gregg-miskelly marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We need to throw if this if is false. |
||
} | ||
catch (AD7Exception e) | ||
{ | ||
m_isStopped = true; | ||
responder.SetError(new ProtocolException(e.Message)); | ||
return; | ||
} | ||
|
||
responder.SetResponse(response); | ||
FireStoppedEvent(thread, StoppedEvent.ReasonValue.Goto); | ||
} | ||
|
||
protected override void HandleGotoTargetsRequestAsync(IRequestResponder<GotoTargetsArguments, GotoTargetsResponse> responder) | ||
|
@@ -1347,6 +1377,7 @@ protected override void HandleGotoTargetsRequestAsync(IRequestResponder<GotoTarg | |
var source = responder.Arguments.Source; | ||
|
||
// Virtual documents don't have paths | ||
// TODO: handle this for disassembly debugging | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I feel like the right want to handle disassembly is to add a |
||
if (source.Path == null) | ||
{ | ||
responder.SetResponse(response); | ||
|
@@ -1369,10 +1400,8 @@ protected override void HandleGotoTargetsRequestAsync(IRequestResponder<GotoTarg | |
while (codeContextsEnum.Next(1, codeContexts, ref nProps) == HRConstants.S_OK) | ||
{ | ||
var codeContext = codeContexts[0]; | ||
|
||
string contextName; | ||
codeContext.GetName(out contextName); | ||
|
||
line = responder.Arguments.Line; | ||
IDebugDocumentContext2 documentContext; | ||
if (codeContext.GetDocumentContext(out documentContext) == HRConstants.S_OK) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same