Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 256337a

Browse files
committed
Work with a gdb-remote target that doesn't handle the
qWatchpointSupportInfo packet correctly. In GDBRemoteCommunicationClient::GetWatchpointSupportInfo, if the response to qWatchpointSupportInfo does not include the 'num' field, then we did not get an answer we understood, mark this target as not supporting that packet. In Target.cpp, rename the very confusingly named CheckIfWatchpointsExhausted to CheckIfWatchpointsSupported, and check the error status returned by Process::GetWatchpointSupportInfo. If we cannot determine what the number of supported watchpoints are, assume that they will work. We'll handle the failure later when we try to create/enable the watchpoint if the Z2 packet isn't supported. Add a gdb_remote_client test case. <rdar://problem/42621432> git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@346561 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7800776 commit 256337a

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from __future__ import print_function
2+
import lldb
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test.decorators import *
5+
from gdbclientutils import *
6+
7+
class TestNoWatchpointSupportInfo(GDBRemoteTestBase):
8+
9+
@skipIfXmlSupportMissing
10+
@skipIfRemote
11+
def test(self):
12+
"""
13+
Test lldb's parsing of the <architecture> tag in the target.xml register
14+
description packet.
15+
"""
16+
class MyResponder(MockGDBServerResponder):
17+
18+
def haltReason(self):
19+
return "T02thread:1ff0d;thread-pcs:10001bc00;"
20+
21+
def threadStopInfo(self, threadnum):
22+
if threadnum == 0x1ff0d:
23+
return "T02thread:1ff0d;thread-pcs:10001bc00;"
24+
25+
def setBreakpoint(self, packet):
26+
if packet.startswith("Z2,"):
27+
return "OK"
28+
29+
def qXferRead(self, obj, annex, offset, length):
30+
if annex == "target.xml":
31+
return """<?xml version="1.0"?>
32+
<target version="1.0">
33+
<architecture>i386:x86-64</architecture>
34+
<feature name="org.gnu.gdb.i386.core">
35+
<reg name="rip" bitsize="64" regnum="0" type="code_ptr" group="general"/>
36+
</feature>
37+
</target>""", False
38+
else:
39+
return None, False
40+
41+
self.server.responder = MyResponder()
42+
if self.TraceOn():
43+
interp = self.dbg.GetCommandInterpreter()
44+
result = lldb.SBCommandReturnObject()
45+
interp.HandleCommand("log enable gdb-remote packets", result)
46+
self.dbg.SetDefaultArchitecture("x86_64")
47+
target = self.dbg.CreateTargetWithFileAndArch(None, None)
48+
49+
process = self.connect(target)
50+
51+
if self.TraceOn():
52+
interp = self.dbg.GetCommandInterpreter()
53+
result = lldb.SBCommandReturnObject()
54+
interp.HandleCommand("target list", result)
55+
print(result.GetOutput())
56+
57+
58+
err = lldb.SBError()
59+
wp = target.WatchAddress(0x100, 8, False, True, err)
60+
if self.TraceOn() and (err.Fail() or wp.IsValid == False):
61+
strm = lldb.SBStream()
62+
err.GetDescription(strm)
63+
print("watchpoint failed: %s" % strm.GetData())
64+
self.assertTrue(wp.IsValid())

source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,12 +1689,17 @@ Status GDBRemoteCommunicationClient::GetWatchpointSupportInfo(uint32_t &num) {
16891689
m_supports_watchpoint_support_info = eLazyBoolYes;
16901690
llvm::StringRef name;
16911691
llvm::StringRef value;
1692+
bool found_num_field = false;
16921693
while (response.GetNameColonValue(name, value)) {
16931694
if (name.equals("num")) {
16941695
value.getAsInteger(0, m_num_supported_hardware_watchpoints);
16951696
num = m_num_supported_hardware_watchpoints;
1697+
found_num_field = true;
16961698
}
16971699
}
1700+
if (found_num_field == false) {
1701+
m_supports_watchpoint_support_info = eLazyBoolNo;
1702+
}
16981703
} else {
16991704
m_supports_watchpoint_support_info = eLazyBoolNo;
17001705
}

source/Target/Target.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,10 +772,16 @@ bool Target::ProcessIsValid() {
772772
return (m_process_sp && m_process_sp->IsAlive());
773773
}
774774

775-
static bool CheckIfWatchpointsExhausted(Target *target, Status &error) {
775+
static bool CheckIfWatchpointsSupported(Target *target, Status &error) {
776776
uint32_t num_supported_hardware_watchpoints;
777777
Status rc = target->GetProcessSP()->GetWatchpointSupportInfo(
778778
num_supported_hardware_watchpoints);
779+
780+
// If unable to determine the # of watchpoints available,
781+
// assume they are supported.
782+
if (rc.Fail())
783+
return true;
784+
779785
if (num_supported_hardware_watchpoints == 0) {
780786
error.SetErrorStringWithFormat(
781787
"Target supports (%u) hardware watchpoint slots.\n",
@@ -814,7 +820,7 @@ WatchpointSP Target::CreateWatchpoint(lldb::addr_t addr, size_t size,
814820
error.SetErrorStringWithFormat("invalid watchpoint type: %d", kind);
815821
}
816822

817-
if (!CheckIfWatchpointsExhausted(this, error))
823+
if (!CheckIfWatchpointsSupported(this, error))
818824
return wp_sp;
819825

820826
// Currently we only support one watchpoint per address, with total number of

0 commit comments

Comments
 (0)