Skip to content

Commit 2294c37

Browse files
authored
Merge pull request #11566 from medismailben/stable/21.x
2 parents 0345bcc + 7f1cc27 commit 2294c37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1702
-248
lines changed

lldb/bindings/python/static-binding/LLDBWrapPython.cpp

Lines changed: 423 additions & 97 deletions
Large diffs are not rendered by default.

lldb/bindings/python/static-binding/lldb.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7350,6 +7350,10 @@ def IsArtificial(self, *args):
73507350
"""
73517351
return _lldb.SBFrame_IsArtificial(self, *args)
73527352

7353+
def IsSynthetic(self):
7354+
r"""IsSynthetic(SBFrame self) -> bool"""
7355+
return _lldb.SBFrame_IsSynthetic(self)
7356+
73537357
def IsHidden(self):
73547358
r"""
73557359
Return whether a frame recognizer decided this frame should not
@@ -12245,6 +12249,56 @@ def GetGenericValue(self):
1224512249
r"""Return the generic pointer if this data structure is a generic type."""
1224612250
return _lldb.SBStructuredData_GetGenericValue(self)
1224712251

12252+
def SetValueForKey(self, key, value):
12253+
r"""
12254+
Set the value corresponding to a key. If this data structure
12255+
is not a dictionary type, reset the type to be dictionary and overwrite
12256+
the previous data.
12257+
"""
12258+
return _lldb.SBStructuredData_SetValueForKey(self, key, value)
12259+
12260+
def SetUnsignedIntegerValue(self, value):
12261+
r"""
12262+
Change the type to unsigned interger and overwrite the previous data with
12263+
the new value.
12264+
"""
12265+
return _lldb.SBStructuredData_SetUnsignedIntegerValue(self, value)
12266+
12267+
def SetSignedIntegerValue(self, value):
12268+
r"""
12269+
Change the type to signed interger and overwrite the previous data with
12270+
the new value.
12271+
"""
12272+
return _lldb.SBStructuredData_SetSignedIntegerValue(self, value)
12273+
12274+
def SetFloatValue(self, value):
12275+
r"""
12276+
Change the type to float and overwrite the previous data with the new
12277+
value.
12278+
"""
12279+
return _lldb.SBStructuredData_SetFloatValue(self, value)
12280+
12281+
def SetBooleanValue(self, value):
12282+
r"""
12283+
Change the type to boolean and overwrite the previous data with the new
12284+
value.
12285+
"""
12286+
return _lldb.SBStructuredData_SetBooleanValue(self, value)
12287+
12288+
def SetStringValue(self, value):
12289+
r"""
12290+
Change the type to string and overwrite the previous data with the new
12291+
value.
12292+
"""
12293+
return _lldb.SBStructuredData_SetStringValue(self, value)
12294+
12295+
def SetGenericValue(self, value):
12296+
r"""
12297+
Change the type to generic and overwrite the previous data with the new
12298+
value.
12299+
"""
12300+
return _lldb.SBStructuredData_SetGenericValue(self, value)
12301+
1224812302
def __repr__(self):
1224912303
r"""__repr__(SBStructuredData self) -> std::string"""
1225012304
return _lldb.SBStructuredData___repr__(self)

lldb/examples/python/crashlog.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,23 +1540,26 @@ def load_crashlog_in_scripted_process(debugger, crashlog_path, options, result):
15401540
}
15411541
)
15421542
)
1543+
1544+
crashlog_sd = lldb.SBStructuredData()
1545+
crashlog_sd.SetGenericValue(
1546+
lldb.SBScriptObject(crashlog, lldb.eScriptLanguagePython)
1547+
)
1548+
structured_data.SetValueForKey("crashlog", crashlog_sd)
1549+
15431550
launch_info = lldb.SBLaunchInfo(None)
15441551
launch_info.SetProcessPluginName("ScriptedProcess")
15451552
launch_info.SetScriptedProcessClassName(
15461553
"crashlog_scripted_process.CrashLogScriptedProcess"
15471554
)
15481555
launch_info.SetScriptedProcessDictionary(structured_data)
1549-
launch_info.SetLaunchFlags(lldb.eLaunchFlagStopAtEntry)
15501556

15511557
error = lldb.SBError()
15521558
process = target.Launch(launch_info, error)
15531559

15541560
if not process or error.Fail():
15551561
raise InteractiveCrashLogException("couldn't launch Scripted Process", error)
15561562

1557-
process.GetScriptedImplementation().set_crashlog(crashlog)
1558-
process.Continue()
1559-
15601563
if not options.skip_status:
15611564

15621565
@contextlib.contextmanager

lldb/examples/python/crashlog_scripted_process.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111

1212
class CrashLogScriptedProcess(ScriptedProcess):
13-
def set_crashlog(self, crashlog):
14-
self.crashlog = crashlog
13+
def parse_crashlog(self):
1514
if self.crashlog.process_id:
1615
if type(self.crashlog.process_id) is int:
1716
self.pid = self.crashlog.process_id
@@ -29,8 +28,6 @@ def set_crashlog(self, crashlog):
2928
if hasattr(self.crashlog, "asb"):
3029
self.extended_thread_info = self.crashlog.asb
3130

32-
crashlog.load_images(self.options, self.loaded_images)
33-
3431
for thread in self.crashlog.threads:
3532
if (
3633
hasattr(thread, "app_specific_backtrace")
@@ -92,10 +89,21 @@ def __init__(self, exe_ctx: lldb.SBExecutionContext, args: lldb.SBStructuredData
9289
no_parallel_image_loading.GetBooleanValue()
9390
)
9491

92+
self.crashlog = None
93+
crashlog = args.GetValueForKey("crashlog")
94+
if crashlog and crashlog.IsValid():
95+
if crashlog.GetType() == lldb.eStructuredDataTypeGeneric:
96+
self.crashlog = crashlog.GetGenericValue()
97+
98+
if not self.crashlog:
99+
# Return error
100+
return
101+
95102
self.pid = super().get_process_id()
96103
self.crashed_thread_idx = 0
97104
self.exception = None
98105
self.extended_thread_info = None
106+
self.parse_crashlog()
99107

100108
def read_memory_at_address(
101109
self, addr: int, size: int, error: lldb.SBError
@@ -104,8 +112,8 @@ def read_memory_at_address(
104112
return lldb.SBData()
105113

106114
def get_loaded_images(self):
107-
# TODO: Iterate over corefile_target modules and build a data structure
108-
# from it.
115+
if len(self.loaded_images) == 0:
116+
self.crashlog.load_images(self.options, self.loaded_images)
109117
return self.loaded_images
110118

111119
def should_stop(self) -> bool:

lldb/examples/python/templates/scripted_process.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,142 @@ def get_extended_info(self):
383383
"""
384384
return self.extended_info
385385

386+
def get_scripted_frame_plugin(self):
387+
"""Get scripted frame plugin name.
388+
389+
Returns:
390+
str: Name of the scripted frame plugin.
391+
"""
392+
return None
393+
394+
395+
class ScriptedFrame(metaclass=ABCMeta):
396+
"""
397+
The base class for a scripted frame.
398+
399+
Most of the base class methods are `@abstractmethod` that need to be
400+
overwritten by the inheriting class.
401+
"""
402+
403+
@abstractmethod
404+
def __init__(self, thread, args):
405+
"""Construct a scripted frame.
406+
407+
Args:
408+
thread (ScriptedThread): The thread owning this frame.
409+
args (lldb.SBStructuredData): A Dictionary holding arbitrary
410+
key/value pairs used by the scripted frame.
411+
"""
412+
self.target = None
413+
self.originating_thread = None
414+
self.thread = None
415+
self.args = None
416+
self.id = None
417+
self.name = None
418+
self.register_info = None
419+
self.register_ctx = {}
420+
self.variables = []
421+
422+
if (
423+
isinstance(thread, ScriptedThread)
424+
or isinstance(thread, lldb.SBThread)
425+
and thread.IsValid()
426+
):
427+
self.target = thread.target
428+
self.process = thread.process
429+
self.originating_thread = thread
430+
self.thread = self.process.GetThreadByIndexID(thread.tid)
431+
self.get_register_info()
432+
433+
@abstractmethod
434+
def get_id(self):
435+
"""Get the scripted frame identifier.
436+
437+
Returns:
438+
int: The identifier of the scripted frame in the scripted thread.
439+
"""
440+
pass
441+
442+
def get_pc(self):
443+
"""Get the scripted frame address.
444+
445+
Returns:
446+
int: The optional address of the scripted frame in the scripted thread.
447+
"""
448+
return None
449+
450+
def get_symbol_context(self):
451+
"""Get the scripted frame symbol context.
452+
453+
Returns:
454+
lldb.SBSymbolContext: The symbol context of the scripted frame in the scripted thread.
455+
"""
456+
return None
457+
458+
def is_inlined(self):
459+
"""Check if the scripted frame is inlined.
460+
461+
Returns:
462+
bool: True if scripted frame is inlined. False otherwise.
463+
"""
464+
return False
465+
466+
def is_artificial(self):
467+
"""Check if the scripted frame is artificial.
468+
469+
Returns:
470+
bool: True if scripted frame is artificial. False otherwise.
471+
"""
472+
return True
473+
474+
def is_hidden(self):
475+
"""Check if the scripted frame is hidden.
476+
477+
Returns:
478+
bool: True if scripted frame is hidden. False otherwise.
479+
"""
480+
return False
481+
482+
def get_function_name(self):
483+
"""Get the scripted frame function name.
484+
485+
Returns:
486+
str: The function name of the scripted frame.
487+
"""
488+
return self.name
489+
490+
def get_display_function_name(self):
491+
"""Get the scripted frame display function name.
492+
493+
Returns:
494+
str: The display function name of the scripted frame.
495+
"""
496+
return self.get_function_name()
497+
498+
def get_variables(self, filters):
499+
"""Get the scripted thread state type.
500+
501+
Args:
502+
filter (lldb.SBVariablesOptions): The filter used to resolve the variables
503+
Returns:
504+
lldb.SBValueList: The SBValueList containing the SBValue for each resolved variable.
505+
Returns None by default.
506+
"""
507+
return None
508+
509+
def get_register_info(self):
510+
if self.register_info is None:
511+
self.register_info = self.originating_thread.get_register_info()
512+
return self.register_info
513+
514+
@abstractmethod
515+
def get_register_context(self):
516+
"""Get the scripted thread register context
517+
518+
Returns:
519+
str: A byte representing all register's value.
520+
"""
521+
pass
386522

387523
class PassthroughScriptedProcess(ScriptedProcess):
388524
driving_target = None

lldb/include/lldb/API/SBFrame.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class LLDB_API SBFrame {
107107

108108
bool IsArtificial() const;
109109

110+
bool IsSynthetic() const;
111+
110112
/// Return whether a frame recognizer decided this frame should not
111113
/// be displayes in backtraces etc.
112114
bool IsHidden() const;

lldb/include/lldb/API/SBStructuredData.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,35 @@ class SBStructuredData {
109109
/// Return the generic pointer if this data structure is a generic type.
110110
lldb::SBScriptObject GetGenericValue() const;
111111

112+
/// Set the value corresponding to a key. If this data structure
113+
/// is not a dictionary type, reset the type to be dictionary and overwrite
114+
/// the previous data.
115+
void SetValueForKey(const char *key, SBStructuredData &value);
116+
117+
/// Change the type to unsigned interger and overwrite the previous data with
118+
/// the new value.
119+
void SetUnsignedIntegerValue(uint64_t value);
120+
121+
/// Change the type to signed interger and overwrite the previous data with
122+
/// the new value.
123+
void SetSignedIntegerValue(int64_t value);
124+
125+
/// Change the type to float and overwrite the previous data with the new
126+
/// value.
127+
void SetFloatValue(double value);
128+
129+
/// Change the type to boolean and overwrite the previous data with the new
130+
/// value.
131+
void SetBooleanValue(bool value);
132+
133+
/// Change the type to string and overwrite the previous data with the new
134+
/// value.
135+
void SetStringValue(const char *value);
136+
137+
/// Change the type to generic and overwrite the previous data with the new
138+
/// value.
139+
void SetGenericValue(SBScriptObject value);
140+
112141
protected:
113142
friend class SBAttachInfo;
114143
friend class SBCommandReturnObject;

lldb/include/lldb/API/SBSymbolContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class LLDB_API SBSymbolContext {
6666
friend class SBTarget;
6767
friend class SBSymbolContextList;
6868

69+
friend class lldb_private::ScriptInterpreter;
6970
friend class lldb_private::python::SWIGBridge;
7071

7172
SBSymbolContext(const lldb_private::SymbolContext &sc_ptr);

lldb/include/lldb/Core/FormatEntity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct Entry {
8080
FrameRegisterFlags,
8181
FrameRegisterByName,
8282
FrameIsArtificial,
83+
FrameKind,
8384
ScriptFrame,
8485
FunctionID,
8586
FunctionDidChange,

lldb/include/lldb/Core/StructuredDataImpl.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,41 @@ class StructuredDataImpl {
8181

8282
void SetObjectSP(const StructuredData::ObjectSP &obj) { m_data_sp = obj; }
8383

84+
void SetValueForKey(llvm::StringRef key,
85+
const StructuredData::ObjectSP &value) {
86+
if (!m_data_sp ||
87+
m_data_sp->GetType() != lldb::eStructuredDataTypeDictionary) {
88+
m_data_sp = StructuredData::FromKeyValue(key, value);
89+
} else if (StructuredData::Dictionary *dict =
90+
m_data_sp->GetAsDictionary()) {
91+
dict->AddItem(key, value);
92+
}
93+
}
94+
95+
void SetUnsignedIntegerValue(uint64_t value) {
96+
m_data_sp = StructuredData::FromInteger(value);
97+
}
98+
99+
void SetSignedIntegerValue(int64_t value) {
100+
m_data_sp = StructuredData::FromInteger(value);
101+
}
102+
103+
void SetFloatValue(double value) {
104+
m_data_sp = StructuredData::FromFloat(value);
105+
}
106+
107+
void SetBooleanValue(bool value) {
108+
m_data_sp = StructuredData::FromBoolean(value);
109+
}
110+
111+
void SetStringValue(std::string value) {
112+
m_data_sp = StructuredData::FromString(std::move(value));
113+
}
114+
115+
void SetGenericValue(void *value) {
116+
m_data_sp = StructuredData::FromGeneric(value);
117+
}
118+
84119
lldb::StructuredDataType GetType() const {
85120
return (m_data_sp ? m_data_sp->GetType() :
86121
lldb::eStructuredDataTypeInvalid);

0 commit comments

Comments
 (0)