Files
clang-p2996/lldb/source/Plugins/SymbolFile/JSON/SymbolFileJSON.h
Jonas Devlieghere cf3524a574 [lldb] Introduce new SymbolFileJSON and ObjectFileJSON
Introduce a new object and symbol file format with the goal of mapping
addresses to symbol names. I'd like to think of is as an extremely
simple textual symtab. The file format consists of a triple, a UUID and
a list of symbols. JSON is used for the encoding, but that's mostly an
implementation detail. The goal of the format was to be simple and human
readable.

The new file format is motivated by two use cases:

 - Stripped binaries: when a binary is stripped, you lose the ability to
   do thing like setting symbolic breakpoints. You can keep the
   unstripped binary around, but if all you need is the stripped
   symbols then that's a lot of overhead. Instead, we could save the
   stripped symbols to a file and load them in the debugger when
   needed. I want to extend llvm-strip to have a mode where it emits
   this new file format.

 - Interactive crashlogs: with interactive crashlogs, if we don't have
   the binary or the dSYM for a particular module, we currently show an
   unnamed symbol for those frames. This is a regression compared to the
   textual format, that has these frames pre-symbolicated. Given that
   this information is available in the JSON crashlog, we need a way to
   tell LLDB about it. With the new symbol file format, we can easily
   synthesize a symbol file for each of those modules and load them to
   symbolicate those frames.

Here's an example of the file format:

 {
     "triple": "arm64-apple-macosx13.0.0",
     "uuid": "36D0CCE7-8ED2-3CA3-96B0-48C1764DA908",
     "symbols": [
         {
             "name": "main",
             "type": "code",
             "size": 32,
             "address": 4294983568
         },
         {
             "name": "foo",
             "type": "code",
             "size": 8,
             "address": 4294983560
         }
     ]
 }

Differential revision: https://reviews.llvm.org/D145180
2023-03-08 20:56:11 -08:00

111 lines
3.3 KiB
C++

//===-- SymbolFileJSON.h ----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_JSON_SYMBOLFILETEXT_H
#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_JSON_SYMBOLFILETEXT_H
#include <map>
#include <optional>
#include <vector>
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/SymbolFile.h"
namespace lldb_private {
class SymbolFileJSON : public lldb_private::SymbolFileCommon {
/// LLVM RTTI support.
static char ID;
public:
/// LLVM RTTI support.
/// \{
bool isA(const void *ClassID) const override {
return ClassID == &ID || SymbolFileCommon::isA(ClassID);
}
static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
/// \}
SymbolFileJSON(lldb::ObjectFileSP objfile_sp);
static void Initialize();
static void Terminate();
static llvm::StringRef GetPluginNameStatic() { return "text"; }
static llvm::StringRef GetPluginDescriptionStatic();
static lldb_private::SymbolFile *
CreateInstance(lldb::ObjectFileSP objfile_sp);
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
uint32_t CalculateAbilities() override;
lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override {
return lldb::eLanguageTypeUnknown;
}
size_t ParseFunctions(CompileUnit &comp_unit) override { return 0; }
bool ParseLineTable(CompileUnit &comp_unit) override { return false; }
bool ParseDebugMacros(CompileUnit &comp_unit) override { return false; }
bool ParseSupportFiles(CompileUnit &comp_unit,
FileSpecList &support_files) override {
return false;
}
size_t ParseTypes(CompileUnit &cu) override { return 0; }
bool ParseImportedModules(
const SymbolContext &sc,
std::vector<lldb_private::SourceModule> &imported_modules) override {
return false;
}
size_t ParseBlocksRecursive(Function &func) override { return 0; }
size_t ParseVariablesForContext(const SymbolContext &sc) override {
return 0;
}
uint32_t CalculateNumCompileUnits() override { return 0; }
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
Type *ResolveTypeUID(lldb::user_id_t type_uid) override { return nullptr; }
std::optional<ArrayInfo> GetDynamicArrayInfoForUID(
lldb::user_id_t type_uid,
const lldb_private::ExecutionContext *exe_ctx) override {
return std::nullopt;
}
bool CompleteType(CompilerType &compiler_type) override { return false; }
uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
lldb::SymbolContextItem resolve_scope,
lldb_private::SymbolContext &sc) override;
void GetTypes(lldb_private::SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
lldb_private::TypeList &type_list) override;
void AddSymbols(Symtab &symtab) override;
private:
lldb::addr_t GetBaseFileAddress();
std::vector<std::pair<uint64_t, std::string>> m_symbols;
};
} // namespace lldb_private
#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_JSON_SYMBOLFILETEXT_H