labath created this revision. labath added reviewers: zturner, jingham, JDevlieghere, clayborg, teemperor. Herald added subscribers: arphaman, aprantl, mgorny.
This patch introduces a "Formats" library, whose goal is to contain serialization and deserialization code for various textual and binary formats that lldb needs to work with. The motivation is to enable building various tools on top of this, which do not need to depend on the entire lldb codebase. (I have written a slightly more elaborate version of this is given in the lldb architecture docs, which I update to mention the new library). LinuxProcMaps is just the beginning here. As the next immediate step I plan to move the Minidump parsing code (currently burried in source/Plugins/Process/minidump) here as well, but in the future I think this library could contain the gdb-remote protocol code (currently in source/Plugins/Process/gdb-remote) and the debug info protocol code (currently in Zach's head). https://reviews.llvm.org/D58972 Files: docs/use/architecture.rst include/lldb/Formats/LinuxProcMaps.h include/lldb/module.modulemap source/CMakeLists.txt source/Formats/CMakeLists.txt source/Formats/LinuxProcMaps.cpp source/Plugins/Process/Linux/CMakeLists.txt source/Plugins/Process/Linux/NativeProcessLinux.cpp source/Plugins/Process/Utility/CMakeLists.txt source/Plugins/Process/Utility/LinuxProcMaps.cpp source/Plugins/Process/Utility/LinuxProcMaps.h source/Plugins/Process/minidump/CMakeLists.txt source/Plugins/Process/minidump/MinidumpParser.cpp unittests/CMakeLists.txt unittests/Formats/CMakeLists.txt unittests/Formats/LinuxProcMapsTest.cpp www/architecture/index.html
Index: www/architecture/index.html =================================================================== --- www/architecture/index.html +++ www/architecture/index.html @@ -38,6 +38,7 @@ <li><a href="#core">Core</a></li> <li><a href="#dataformatters">DataFormatters</a></li> <li><a href="#expression">Expression</a></li> + <li><a href="#formats">Formats</a></li> <li><a href="#host">Host</a></li> <li><a href="#interpreter">Interpreter</a></li> <li><a href="#symbol">Symbol</a></li> @@ -186,6 +187,32 @@ </div> <div class="postfooter"></div> </div> + <a name="formats"></a> + <div class="post"> + <h1 class ="postheader">Formats</h1> + <div class="postcontent"> + <p> + The Formats module contains the code for + handling various types of data formats that + LLDB needs to work with. This includes + serialization and deserialization code for + all kinds of textual and binary formats, + ranging from the contents of the linux + /proc/PID/maps file, to windows minidump + files. The goal of this library is to present + the data in an easily accessible fashion. + However, it does not connect this data to + higher level lldb concepts (Targets, Modules, + ...) -- that's the job of individual plugins. + The goal of this is so that another + application (or lldb-server) can use the + (de)serialization code from this library + without depending on the lldb object model, + or being constrained by it. + </p> + </div> + <div class="postfooter"></div> + </div> <a name="host"></a> <div class="post"> <h1 class ="postheader">Host</h1> Index: unittests/Formats/LinuxProcMapsTest.cpp =================================================================== --- /dev/null +++ unittests/Formats/LinuxProcMapsTest.cpp @@ -0,0 +1,32 @@ +//===-- LinuxProcMapsTest.cpp -----------------------------------*- 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 +// +//===----------------------------------------------------------------------===// + +#include "lldb/Formats/LinuxProcMaps.h" +#include "lldb/Utility/MemoryRegionInfo.h" +#include "lldb/Utility/Status.h" +#include "gtest/gtest.h" + +using namespace lldb_private; + +TEST(LinuxProcMaps, ParseLinuxMapRegions) { + std::vector<MemoryRegionInfo> Infos; + ParseLinuxMapRegions("557bdd004000-557bdd0bc000 r-xp 00000000 fd:01 3012381 " + " /bin/bash", + [&](const MemoryRegionInfo &Info, const Status &ST) { + EXPECT_TRUE(ST.Success()); + Infos.push_back(Info); + return true; + }); + ASSERT_EQ(1u, Infos.size()); + EXPECT_EQ(0x557bdd004000u, Infos[0].GetRange().GetRangeBase()); + EXPECT_EQ(0x557bdd0bc000u, Infos[0].GetRange().GetRangeEnd()); + EXPECT_EQ(MemoryRegionInfo::eYes, Infos[0].GetReadable()); + EXPECT_EQ(MemoryRegionInfo::eNo, Infos[0].GetWritable()); + EXPECT_EQ(MemoryRegionInfo::eYes, Infos[0].GetExecutable()); + EXPECT_STREQ("/bin/bash", Infos[0].GetName().GetCString()); +} Index: unittests/Formats/CMakeLists.txt =================================================================== --- /dev/null +++ unittests/Formats/CMakeLists.txt @@ -0,0 +1,8 @@ +add_lldb_unittest(LLDBFormatsTests + LinuxProcMapsTest.cpp + + LINK_LIBS + lldbFormats + LINK_COMPONENTS + Support + ) Index: unittests/CMakeLists.txt =================================================================== --- unittests/CMakeLists.txt +++ unittests/CMakeLists.txt @@ -63,6 +63,7 @@ add_subdirectory(Disassembler) add_subdirectory(Editline) add_subdirectory(Expression) +add_subdirectory(Formats) add_subdirectory(Host) add_subdirectory(Interpreter) add_subdirectory(Language) Index: source/Plugins/Process/minidump/MinidumpParser.cpp =================================================================== --- source/Plugins/Process/minidump/MinidumpParser.cpp +++ source/Plugins/Process/minidump/MinidumpParser.cpp @@ -11,7 +11,7 @@ #include "RegisterContextMinidump_x86_32.h" #include "lldb/Utility/LLDBAssert.h" -#include "Plugins/Process/Utility/LinuxProcMaps.h" +#include "lldb/Formats/LinuxProcMaps.h" // C includes // C++ includes Index: source/Plugins/Process/minidump/CMakeLists.txt =================================================================== --- source/Plugins/Process/minidump/CMakeLists.txt +++ source/Plugins/Process/minidump/CMakeLists.txt @@ -10,6 +10,7 @@ LINK_LIBS lldbCore + lldbFormats lldbTarget lldbUtility lldbPluginProcessUtility Index: source/Plugins/Process/Utility/CMakeLists.txt =================================================================== --- source/Plugins/Process/Utility/CMakeLists.txt +++ source/Plugins/Process/Utility/CMakeLists.txt @@ -5,7 +5,6 @@ HistoryThread.cpp HistoryUnwind.cpp InferiorCallPOSIX.cpp - LinuxProcMaps.cpp LinuxSignals.cpp MipsLinuxSignals.cpp NativeRegisterContextRegisterInfo.cpp Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp =================================================================== --- source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -44,7 +44,7 @@ #include "NativeThreadLinux.h" #include "Plugins/Process/POSIX/ProcessPOSIXLog.h" -#include "Plugins/Process/Utility/LinuxProcMaps.h" +#include "lldb/Formats/LinuxProcMaps.h" #include "Procfs.h" #include <linux/unistd.h> Index: source/Plugins/Process/Linux/CMakeLists.txt =================================================================== --- source/Plugins/Process/Linux/CMakeLists.txt +++ source/Plugins/Process/Linux/CMakeLists.txt @@ -13,6 +13,7 @@ LINK_LIBS lldbCore + lldbFormats lldbHost lldbSymbol lldbTarget Index: source/Formats/LinuxProcMaps.cpp =================================================================== --- source/Formats/LinuxProcMaps.cpp +++ source/Formats/LinuxProcMaps.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "LinuxProcMaps.h" +#include "lldb/Formats/LinuxProcMaps.h" #include "lldb/Utility/MemoryRegionInfo.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/StringExtractor.h" Index: source/Formats/CMakeLists.txt =================================================================== --- /dev/null +++ source/Formats/CMakeLists.txt @@ -0,0 +1,8 @@ +add_lldb_library(lldbFormats + LinuxProcMaps.cpp + + LINK_LIBS + lldbUtility + LINK_COMPONENTS + Support + ) Index: source/CMakeLists.txt =================================================================== --- source/CMakeLists.txt +++ source/CMakeLists.txt @@ -75,6 +75,7 @@ add_subdirectory(Core) add_subdirectory(DataFormatters) add_subdirectory(Expression) +add_subdirectory(Formats) add_subdirectory(Host) add_subdirectory(Initialization) add_subdirectory(Interpreter) Index: include/lldb/module.modulemap =================================================================== --- include/lldb/module.modulemap +++ include/lldb/module.modulemap @@ -6,6 +6,13 @@ module * { export * } } +module lldb_Formats { + requires cplusplus + + umbrella "Formats" + module * { export * } +} + module lldb_Host { requires cplusplus Index: source/Plugins/Process/Utility/LinuxProcMaps.h =================================================================== --- /dev/null +++ source/Plugins/Process/Utility/LinuxProcMaps.h @@ -1,27 +0,0 @@ -//===-- LinuxProcMaps.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 liblldb_LinuxProcMaps_H_ -#define liblldb_LinuxProcMaps_H_ - -#include "lldb/lldb-forward.h" -#include "llvm/ADT/StringRef.h" -#include <functional> - - -namespace lldb_private { - -typedef std::function<bool(const lldb_private::MemoryRegionInfo &, - const lldb_private::Status &)> LinuxMapCallback; - -void ParseLinuxMapRegions(llvm::StringRef linux_map, - LinuxMapCallback const &callback); - -} // namespace lldb_private - -#endif // liblldb_LinuxProcMaps_H_ Index: docs/use/architecture.rst =================================================================== --- docs/use/architecture.rst +++ docs/use/architecture.rst @@ -123,6 +123,19 @@ re-evaluated each time an expression needs to be evaluated, or JIT'ed up into code that can be run on the process being debugged. +Formats +------- + +The Formats module contains the code for handling various types of data formats +that LLDB needs to work with. This includes serialization and deserialization +code for all kinds of textual and binary formats, ranging from the contents of +the linux /proc/PID/maps file, to windows minidump files. The goal of this +library is to present the data in an easily accessible fashion. However, it does +not connect this data to higher level lldb concepts (Targets, Modules, ...) -- +that's the job of individual plugins. The goal of this is so that another +application (or lldb-server) can use the (de)serialization code from this +library without depending on the lldb object model, or being constrained by it. + Host ----
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits