Skip to content

Commit 449ca01

Browse files
committed
[Reproducer] Include the this pointer in the API log.
The new centralized way of doing API logging through the reproducer macros is lacking a way to easily correlate instances of API objects. Logging the this pointer makes that significantly easier. For methods this is now always passed as the first argument, similar to the self argument in Python. This patch also adds a test case for API logging, which uncovered that we were not quoting strings. Differential revision: https://reviews.llvm.org/D67538 llvm-svn: 371885
1 parent 5560270 commit 449ca01

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

lldb/include/lldb/Utility/ReproducerInstrumentation.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ inline void stringify_append(llvm::raw_string_ostream &ss, const T *t) {
4040
template <>
4141
inline void stringify_append<char>(llvm::raw_string_ostream &ss,
4242
const char *t) {
43-
ss << t;
43+
ss << '\"' << t << '\"';
4444
}
4545

4646
template <typename Head>
@@ -105,8 +105,8 @@ template <typename... Ts> inline std::string stringify_args(const Ts &... ts) {
105105
}
106106

107107
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature, ...) \
108-
lldb_private::repro::Recorder sb_recorder(LLVM_PRETTY_FUNCTION, \
109-
stringify_args(__VA_ARGS__)); \
108+
lldb_private::repro::Recorder sb_recorder( \
109+
LLVM_PRETTY_FUNCTION, stringify_args(*this, __VA_ARGS__)); \
110110
if (lldb_private::repro::InstrumentationData data = \
111111
LLDB_GET_INSTRUMENTATION_DATA()) { \
112112
sb_recorder.Record( \
@@ -117,8 +117,8 @@ template <typename... Ts> inline std::string stringify_args(const Ts &... ts) {
117117
}
118118

119119
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature, ...) \
120-
lldb_private::repro::Recorder sb_recorder(LLVM_PRETTY_FUNCTION, \
121-
stringify_args(__VA_ARGS__)); \
120+
lldb_private::repro::Recorder sb_recorder( \
121+
LLVM_PRETTY_FUNCTION, stringify_args(*this, __VA_ARGS__)); \
122122
if (lldb_private::repro::InstrumentationData data = \
123123
LLDB_GET_INSTRUMENTATION_DATA()) { \
124124
sb_recorder.Record( \
@@ -129,7 +129,8 @@ template <typename... Ts> inline std::string stringify_args(const Ts &... ts) {
129129
}
130130

131131
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method) \
132-
lldb_private::repro::Recorder sb_recorder(LLVM_PRETTY_FUNCTION); \
132+
lldb_private::repro::Recorder sb_recorder(LLVM_PRETTY_FUNCTION, \
133+
stringify_args(*this)); \
133134
if (lldb_private::repro::InstrumentationData data = \
134135
LLDB_GET_INSTRUMENTATION_DATA()) { \
135136
sb_recorder.Record(data.GetSerializer(), data.GetRegistry(), \
@@ -139,7 +140,8 @@ template <typename... Ts> inline std::string stringify_args(const Ts &... ts) {
139140
}
140141

141142
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method) \
142-
lldb_private::repro::Recorder sb_recorder(LLVM_PRETTY_FUNCTION); \
143+
lldb_private::repro::Recorder sb_recorder(LLVM_PRETTY_FUNCTION, \
144+
stringify_args(*this)); \
143145
if (lldb_private::repro::InstrumentationData data = \
144146
LLDB_GET_INSTRUMENTATION_DATA()) { \
145147
sb_recorder.Record( \
@@ -542,9 +544,7 @@ class Serializer {
542544
SerializeAll(tail...);
543545
}
544546

545-
void SerializeAll() {
546-
m_stream.flush();
547-
}
547+
void SerializeAll() { m_stream.flush(); }
548548

549549
private:
550550
/// Serialize pointers. We need to differentiate between pointers to
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Test API logging.
3+
"""
4+
5+
import re
6+
7+
import lldb
8+
import lldbsuite.test.lldbutil as lldbutil
9+
from lldbsuite.test.lldbtest import *
10+
11+
12+
class APILogTestCase(TestBase):
13+
14+
mydir = TestBase.compute_mydir(__file__)
15+
16+
NO_DEBUG_INFO_TESTCASE = True
17+
18+
def test_api_log(self):
19+
"""Test API logging"""
20+
logfile = os.path.join(self.getBuildDir(), "api-log.txt")
21+
22+
def cleanup():
23+
if os.path.exists(logfile):
24+
os.unlink(logfile)
25+
26+
self.addTearDownHook(cleanup)
27+
self.expect("log enable lldb api -f {}".format(logfile))
28+
29+
self.dbg.SetDefaultArchitecture(None)
30+
self.dbg.GetScriptingLanguage(None)
31+
target = self.dbg.CreateTarget(None)
32+
33+
print(logfile)
34+
with open(logfile, 'r') as f:
35+
log = f.read()
36+
37+
# Find the debugger addr.
38+
debugger_addr = re.findall(
39+
r"lldb::SBDebugger::GetScriptingLanguage\(const char \*\) \(0x([0-9a-fA-F]+),",
40+
log)[0]
41+
42+
get_scripting_language = 'lldb::ScriptLanguage lldb::SBDebugger::GetScriptingLanguage(const char *) (0x{}, "")'.format(
43+
debugger_addr)
44+
create_target = 'lldb::SBTarget lldb::SBDebugger::CreateTarget(const char *) (0x{}, "")'.format(
45+
debugger_addr)
46+
47+
self.assertTrue(get_scripting_language in log)
48+
self.assertTrue(create_target in log)

0 commit comments

Comments
 (0)