Skip to content

Commit 4a1c410

Browse files
LucasStejawilk
andcommitted
[SOL] LLDB for LLVM 19 (#145)
* [SOL] lldb: pretty print instructions * [SOL] lldb: skip ranges with DW_AT_low_pc equal to zero * [SOL] lldb: Add solana-lldb wrapper This adds a wrapper around the LLDB executable that resides in the same directory. Once we start to distribute LLDB in sbf-tools, the wrapper + scripts can be put into the same directory as the LLDB executable. Invoking ./solana-lldb will pre-load helper functions to print rust as well as solana types (e.g. pubkeys in base58 or auto deref of accounts) and then start the LLDB executable. * [SOL] Revamp LLDB for SBF --------- Co-authored-by: wj <[email protected]>
1 parent 92f6254 commit 4a1c410

File tree

16 files changed

+1148
-17
lines changed

16 files changed

+1148
-17
lines changed

lldb/include/lldb/Core/Opcode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLDB_CORE_OPCODE_H
1010
#define LLDB_CORE_OPCODE_H
1111

12+
#include "lldb/Utility/ArchSpec.h"
1213
#include "lldb/Utility/Endian.h"
1314
#include "lldb/lldb-enumerations.h"
1415

@@ -199,7 +200,7 @@ class Opcode {
199200
}
200201
}
201202

202-
int Dump(Stream *s, uint32_t min_byte_width);
203+
int Dump(Stream *s, uint32_t min_byte_width, const ArchSpec &arch);
203204

204205
const void *GetOpcodeBytes() const {
205206
return ((m_type == Opcode::eTypeBytes) ? m_data.inst.bytes : nullptr);

lldb/include/lldb/Utility/ArchSpec.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ class ArchSpec {
107107
};
108108

109109
enum SBFSubType {
110-
eSBFSubType_sbf,
110+
eSBFSubType_sbfv0,
111+
eSBFSubType_sbfv1,
111112
eSBFSubType_sbfv2,
113+
eSBFSubType_sbfv3,
112114
};
113115

114116
enum RISCVSubType {
@@ -247,8 +249,10 @@ class ArchSpec {
247249
eCore_wasm32,
248250

249251
eCore_bpf,
250-
eCore_sbf,
252+
eCore_sbfv0,
253+
eCore_sbfv1,
251254
eCore_sbfv2,
255+
eCore_sbfv3,
252256

253257
kNumCores,
254258

lldb/scripts/solana/lldb_commands

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
type synthetic add -l lldb_lookup.synthetic_lookup -x ".*" --category Rust
2+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)String$" --category Rust
3+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?str$" --category Rust
4+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?\\[.+\\]$" --category Rust
5+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::ffi::([a-z_]+::)+)OsString$" --category Rust
6+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Vec<.+>$" --category Rust
7+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)VecDeque<.+>$" --category Rust
8+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)BTreeSet<.+>$" --category Rust
9+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)BTreeMap<.+>$" --category Rust
10+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::collections::([a-z_]+::)+)HashMap<.+>$" --category Rust
11+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::collections::([a-z_]+::)+)HashSet<.+>$" --category Rust
12+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Rc<.+>$" --category Rust
13+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Arc<.+>$" --category Rust
14+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)Cell<.+>$" --category Rust
15+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)Ref<.+>$" --category Rust
16+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefMut<.+>$" --category Rust
17+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefCell<.+>$" --category Rust
18+
type category enable Rust

lldb/scripts/solana/lldb_lookup.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import lldb
2+
3+
from lldb_providers import *
4+
from rust_types import RustType, classify_struct, classify_union
5+
6+
7+
# BACKCOMPAT: rust 1.35
8+
def is_hashbrown_hashmap(hash_map):
9+
return len(hash_map.type.fields) == 1
10+
11+
12+
def classify_rust_type(type):
13+
type_class = type.GetTypeClass()
14+
if type_class == lldb.eTypeClassStruct:
15+
return classify_struct(type.name, type.fields)
16+
if type_class == lldb.eTypeClassUnion:
17+
return classify_union(type.fields)
18+
19+
return RustType.OTHER
20+
21+
22+
def summary_lookup(valobj, dict):
23+
# type: (SBValue, dict) -> str
24+
"""Returns the summary provider for the given value"""
25+
rust_type = classify_rust_type(valobj.GetType())
26+
27+
if rust_type == RustType.STD_STRING:
28+
return StdStringSummaryProvider(valobj, dict)
29+
if rust_type == RustType.STD_OS_STRING:
30+
return StdOsStringSummaryProvider(valobj, dict)
31+
if rust_type == RustType.STD_STR:
32+
return StdStrSummaryProvider(valobj, dict)
33+
34+
if rust_type == RustType.STD_VEC:
35+
return SizeSummaryProvider(valobj, dict)
36+
if rust_type == RustType.STD_VEC_DEQUE:
37+
return SizeSummaryProvider(valobj, dict)
38+
if rust_type == RustType.STD_SLICE:
39+
return SizeSummaryProvider(valobj, dict)
40+
41+
if rust_type == RustType.STD_HASH_MAP:
42+
return SizeSummaryProvider(valobj, dict)
43+
if rust_type == RustType.STD_HASH_SET:
44+
return SizeSummaryProvider(valobj, dict)
45+
46+
if rust_type == RustType.STD_RC:
47+
return StdRcSummaryProvider(valobj, dict)
48+
if rust_type == RustType.STD_ARC:
49+
return StdRcSummaryProvider(valobj, dict)
50+
51+
if rust_type == RustType.STD_REF:
52+
return StdRefSummaryProvider(valobj, dict)
53+
if rust_type == RustType.STD_REF_MUT:
54+
return StdRefSummaryProvider(valobj, dict)
55+
if rust_type == RustType.STD_REF_CELL:
56+
return StdRefSummaryProvider(valobj, dict)
57+
58+
return ""
59+
60+
61+
def synthetic_lookup(valobj, dict):
62+
# type: (SBValue, dict) -> object
63+
"""Returns the synthetic provider for the given value"""
64+
rust_type = classify_rust_type(valobj.GetType())
65+
66+
if rust_type == RustType.STRUCT:
67+
return StructSyntheticProvider(valobj, dict)
68+
if rust_type == RustType.STRUCT_VARIANT:
69+
return StructSyntheticProvider(valobj, dict, is_variant=True)
70+
if rust_type == RustType.TUPLE:
71+
return TupleSyntheticProvider(valobj, dict)
72+
if rust_type == RustType.TUPLE_VARIANT:
73+
return TupleSyntheticProvider(valobj, dict, is_variant=True)
74+
if rust_type == RustType.EMPTY:
75+
return EmptySyntheticProvider(valobj, dict)
76+
if rust_type == RustType.REGULAR_ENUM:
77+
discriminant = valobj.GetChildAtIndex(0).GetChildAtIndex(0).GetValueAsUnsigned()
78+
return synthetic_lookup(valobj.GetChildAtIndex(discriminant), dict)
79+
if rust_type == RustType.SINGLETON_ENUM:
80+
return synthetic_lookup(valobj.GetChildAtIndex(0), dict)
81+
82+
if rust_type == RustType.STD_VEC:
83+
return StdVecSyntheticProvider(valobj, dict)
84+
if rust_type == RustType.STD_VEC_DEQUE:
85+
return StdVecDequeSyntheticProvider(valobj, dict)
86+
if rust_type == RustType.STD_SLICE:
87+
return StdSliceSyntheticProvider(valobj, dict)
88+
89+
if rust_type == RustType.STD_HASH_MAP:
90+
if is_hashbrown_hashmap(valobj):
91+
return StdHashMapSyntheticProvider(valobj, dict)
92+
else:
93+
return StdOldHashMapSyntheticProvider(valobj, dict)
94+
if rust_type == RustType.STD_HASH_SET:
95+
hash_map = valobj.GetChildAtIndex(0)
96+
if is_hashbrown_hashmap(hash_map):
97+
return StdHashMapSyntheticProvider(valobj, dict, show_values=False)
98+
else:
99+
return StdOldHashMapSyntheticProvider(hash_map, dict, show_values=False)
100+
101+
if rust_type == RustType.STD_RC:
102+
return StdRcSyntheticProvider(valobj, dict)
103+
if rust_type == RustType.STD_ARC:
104+
return StdRcSyntheticProvider(valobj, dict, is_atomic=True)
105+
106+
if rust_type == RustType.STD_CELL:
107+
return StdCellSyntheticProvider(valobj, dict)
108+
if rust_type == RustType.STD_REF:
109+
return StdRefSyntheticProvider(valobj, dict)
110+
if rust_type == RustType.STD_REF_MUT:
111+
return StdRefSyntheticProvider(valobj, dict)
112+
if rust_type == RustType.STD_REF_CELL:
113+
return StdRefSyntheticProvider(valobj, dict, is_cell=True)
114+
115+
return DefaultSynthteticProvider(valobj, dict)

0 commit comments

Comments
 (0)