AK: Add a getter to JsonValue to get machine-native addresses

This commit is contained in:
Gunnar Beutner 2021-07-21 19:57:05 +02:00 committed by Andreas Kling
parent 36e36507d5
commit 11e02f222d
3 changed files with 14 additions and 9 deletions

View file

@ -91,6 +91,15 @@ public:
u32 to_u32(u32 default_value = 0) const { return to_number<u32>(default_value); }
u64 to_u64(u64 default_value = 0) const { return to_number<u64>(default_value); }
FlatPtr to_addr(FlatPtr default_value = 0) const
{
#ifdef __LP64__
return to_u64(default_value);
#else
return to_u32(default_value);
#endif
}
bool to_bool(bool default_value = false) const
{
if (!is_bool())

View file

@ -108,7 +108,7 @@ Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid)
stack.ensure_capacity(json.value().as_array().size());
for (auto& value : json.value().as_array().values()) {
stack.append(value.to_u32());
stack.append(value.to_addr());
}
}
@ -129,8 +129,8 @@ Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid)
for (auto& region_value : json.value().as_array().values()) {
auto& region = region_value.as_object();
auto name = region.get("name").to_string();
auto address = region.get("address").to_u32();
auto size = region.get("size").to_u32();
auto address = region.get("address").to_addr();
auto size = region.get("size").to_addr();
String path;
if (name == "/usr/lib/Loader.so") {

View file

@ -55,16 +55,12 @@ int main(int argc, char** argv)
Vector<JsonValue> sorted_regions = json.value().as_array().values();
quick_sort(sorted_regions, [](auto& a, auto& b) {
return a.as_object().get("address").to_u64() < b.as_object().get("address").to_u64();
return a.as_object().get("address").to_addr() < b.as_object().get("address").to_addr();
});
for (auto& value : sorted_regions) {
auto& map = value.as_object();
#if ARCH(I386)
auto address = map.get("address").to_u32();
#else
auto address = map.get("address").to_u64();
#endif
auto address = map.get("address").to_addr();
auto size = map.get("size").to_string();
auto access = String::formatted("{}{}{}{}{}",