Skip to content

Commit b8bfa53

Browse files
authored
MIEngine: Fix multi-breakpoint gdb/mi information parsing (#1435)
This PR fixes gdb/mi breakpoint information parsing for breakpoints that bind to multiple locations, which have a '<MULTIPLE>' in the addr field. According to https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Breakpoint-Information.html#GDB_002fMI-Breakpoint-Information the locations field contains the list of locations for this breakpoint type. This list of locations is used then to create the bound breakpoints for the specific breakpoint. Signed-off-by: Andria Pazarloglou <androniki.pazarloglou@intel.com>
1 parent 8ce5af7 commit b8bfa53

4 files changed

Lines changed: 24 additions & 25 deletions

File tree

src/MIDebugEngine/Engine.Impl/BreakpointManager.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,13 @@ public async Task BreakpointModified(object sender, EventArgs args)
5858
string bkptId = null;
5959
//
6060
// =breakpoint-modified,
61-
// bkpt ={number="2",type="breakpoint",disp="keep",enabled="y",addr="<MULTIPLE>",times="0",original-location="main.cpp:220"},
61+
// bkpt ={number="2",type="breakpoint",disp="keep",enabled="y",addr="<MULTIPLE>",times="0",original-location="main.cpp:220"},locations=[
6262
// { number="2.1",enabled="y",addr="0x9c2149a9",func="Foo::bar<int>(int)",file="main.cpp",fullname="C:\\\\...\\\\main.cpp",line="220",thread-groups=["i1"]},
63-
// { number="2.2",enabled="y",addr="0x9c2149f2",func="Foo::bar<float>(float)",file="main.cpp",fullname="C:\\\\...\\\\main.cpp",line="220",thread-groups=["i1"]}
63+
// { number="2.2",enabled="y",addr="0x9c2149f2",func="Foo::bar<float>(float)",file="main.cpp",fullname="C:\\\\...\\\\main.cpp",line="220",thread-groups=["i1"]}]}
6464
// note: the ".x" part of the breakpoint number never appears in stopping events, that is, when executing at one of these addresses
6565
// the stopping event delivered contains bkptno="2"
66-
if (bkpt is MICore.ValueListValue)
67-
{
68-
MICore.ValueListValue list = bkpt as MICore.ValueListValue;
69-
bkptId = list.Content[0].FindString("number"); // 0 is the "<MULTIPLE>" entry
70-
}
71-
else
72-
{
73-
bkptId = bkpt.FindString("number");
74-
}
66+
bkptId = bkpt.FindString("number");
67+
7568
AD7PendingBreakpoint pending = CodeBreakpoints.FirstOrDefault((p) => { return p.BreakpointId == bkptId; });
7669
if (pending == null)
7770
{

src/MIDebugEngine/Engine.Impl/Breakpoints.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,11 @@ private static async Task<BindResult> EvalBindResult(Results bindResult, AD7Pend
146146
if (b is TupleValue)
147147
{
148148
bkpt = b as TupleValue;
149-
}
150-
else if (b is ValueListValue)
151-
{
152-
// "<MULTIPLE>" sometimes includes a list of bound breakpoints
153-
list = b as ValueListValue;
154-
bkpt = list.Content[0] as TupleValue;
149+
// The locations field is present if the breakpoint has multiple locations.
150+
if (b.TryFind("locations", out var locations) && locations is ValueListValue)
151+
{
152+
list = (ValueListValue) locations;
153+
}
155154
}
156155
}
157156
else
@@ -189,9 +188,9 @@ private static async Task<BindResult> EvalBindResult(Results bindResult, AD7Pend
189188
else // <MULTIPLE> with list of addresses
190189
{
191190
BindResult res = new BindResult(bp);
192-
for (int i = 1; i < list.Content.Length; ++i)
191+
foreach (var t in list.Content)
193192
{
194-
BoundBreakpoint bbp = await bp.GetBoundBreakpoint(list.Content[i] as TupleValue);
193+
BoundBreakpoint bbp = await bp.GetBoundBreakpoint(t as TupleValue);
195194
res.BoundBreakpoints.Add(bbp);
196195
}
197196
return res;
@@ -290,12 +289,13 @@ internal async Task<List<BoundBreakpoint>> BindAddresses(ResultValue bkpt)
290289
return resultList;
291290
}
292291
BoundBreakpoint bbp = null;
293-
if (bkpt is ValueListValue)
292+
293+
// The locations field is present if the breakpoint has multiple locations.
294+
if (bkpt.TryFind("locations", out var locations) && locations is ValueListValue list)
294295
{
295-
var list = (ValueListValue)bkpt;
296-
for (int i = 1; i < list.Content.Length; ++i)
296+
foreach (var t in list.Content)
297297
{
298-
bbp = await GetBoundBreakpoint(list.Content[i] as TupleValue);
298+
bbp = await GetBoundBreakpoint(t as TupleValue);
299299
if (bbp != null)
300300
resultList.Add(bbp);
301301
}

test/CppTests/Tests/BreakpointTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void FunctionBreakpointsBasic(ITestSettings settings)
125125
runner.Launch(settings.DebuggerSettings, debuggee, "-fCalling");
126126

127127
this.Comment("Set initial function breakpoints");
128-
FunctionBreakpoints functionBreakpoints = new FunctionBreakpoints("Arguments::CoreRun", "Calling::CoreRun", "a()");
128+
FunctionBreakpoints functionBreakpoints = new FunctionBreakpoints("Arguments::CoreRun", "Calling::CoreRun", "a");
129129
runner.SetFunctionBreakpoints(functionBreakpoints);
130130

131131
this.Comment("Launch and run until first initial breakpoint");
@@ -137,7 +137,7 @@ public void FunctionBreakpointsBasic(ITestSettings settings)
137137
.AfterContinue();
138138

139139
this.Comment("Remove and replace third initial function breakpoint while in break mode");
140-
functionBreakpoints.Remove("a()");
140+
functionBreakpoints.Remove("a");
141141
functionBreakpoints.Add("b()");
142142
runner.SetFunctionBreakpoints(functionBreakpoints);
143143

test/CppTests/debuggees/kitchensink/src/calling.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,10 @@ void Calling::CoreRun()
5252
this->Log("Calling variable arg function.");
5353
double ave = average(10, 1.0, 3.0, 4.5, 11.0, -30.0, 17.4, 2.1, -4.0, 0.0, 12.1);
5454
this->Log("Average ", ave);
55+
}
56+
57+
int a(int count)
58+
{
59+
b();
60+
return count - 1;
5561
}

0 commit comments

Comments
 (0)