[Lldb-commits] [PATCH] D42488: Remove ObjectFile usage from HostLinux::GetProcessInfo
labath created this revision. labath added reviewers: eugene, krytarowski. Herald added subscribers: hintonda, mgorny. The ObjectFile class was used to determine the architecture of a running process by inspecting it's main executable. There were two issues with this: - it's in the wrong layer - the call can be very expensive (it can end up computing the crc of the whole file). Since the process is running on the host, ideally we would be able to just query the data straight from the OS like darwin does, but there doesn't seem to be a reasonable way to do that. So, this fixes the layering issue by using the llvm object library to inspect the file. Since we know the process is already running on the host, we just need to peek at a few bytes of the elf header to determine whether it's 32- or 64-bit (which should make this faster as well). Pretty much the same logic was implemented in NativeProcessProtocol::ResolveProcessArchitecture, so I delete this logic and replace calls with GetProcessInfo. https://reviews.llvm.org/D42488 Files: include/lldb/Host/common/NativeProcessProtocol.h include/lldb/Utility/ArchSpec.h source/Host/CMakeLists.txt source/Host/common/NativeProcessProtocol.cpp source/Host/linux/Host.cpp source/Plugins/Process/Linux/NativeProcessLinux.cpp source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp source/Utility/ArchSpec.cpp unittests/Host/linux/HostTest.cpp Index: unittests/Host/linux/HostTest.cpp === --- unittests/Host/linux/HostTest.cpp +++ unittests/Host/linux/HostTest.cpp @@ -45,4 +45,7 @@ ASSERT_TRUE(Info.GroupIDIsValid()); EXPECT_EQ(getegid(), Info.GetGroupID()); + + EXPECT_EQ(HostInfo::GetArchitecture(HostInfo::eArchKindDefault), +Info.GetArchitecture()); } Index: source/Utility/ArchSpec.cpp === --- source/Utility/ArchSpec.cpp +++ source/Utility/ArchSpec.cpp @@ -1416,6 +1416,11 @@ return lhs_core < rhs_core; } + +bool lldb_private::operator==(const ArchSpec &lhs, const ArchSpec &rhs) { + return lhs.GetCore() == rhs.GetCore(); +} + bool ArchSpec::IsFullySpecifiedTriple() const { const auto &user_specified_triple = GetTriple(); Index: source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp === --- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp +++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp @@ -93,17 +93,19 @@ } LLDB_LOG(log, "inferior started, now in stopped state"); - ArchSpec arch; - if ((status = ResolveProcessArchitecture(pid, arch)).Fail()) -return status.ToError(); + ProcessInstanceInfo Info; + if (!Host::GetProcessInfo(pid, Info)) { +return llvm::make_error("Cannot get process architecture", + llvm::inconvertibleErrorCode()); + } // Set the architecture to the exe architecture. LLDB_LOG(log, "pid = {0:x}, detected architecture {1}", pid, - arch.GetArchitectureName()); + Info.GetArchitecture().GetArchitectureName()); std::unique_ptr process_up(new NativeProcessNetBSD( pid, launch_info.GetPTY().ReleaseMasterFileDescriptor(), native_delegate, - arch, mainloop)); + Info.GetArchitecture(), mainloop)); status = process_up->ReinitializeThreads(); if (status.Fail()) @@ -124,13 +126,14 @@ LLDB_LOG(log, "pid = {0:x}", pid); // Retrieve the architecture for the running process. - ArchSpec arch; - Status status = ResolveProcessArchitecture(pid, arch); - if (!status.Success()) -return status.ToError(); + ProcessInstanceInfo Info; + if (!Host::GetProcessInfo(pid, Info)) { +return llvm::make_error("Cannot get process architecture", + llvm::inconvertibleErrorCode()); + } - std::unique_ptr process_up( - new NativeProcessNetBSD(pid, -1, native_delegate, arch, mainloop)); + std::unique_ptr process_up(new NativeProcessNetBSD( + pid, -1, native_delegate, Info.GetArchitecture(), mainloop)); status = process_up->Attach(); if (!status.Success()) Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp === --- source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -26,7 +26,6 @@ #include "lldb/Core/EmulateInstruction.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/RegisterValue.h" -#include "lldb/Utility/State.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostProcess.h" #include "lldb/Host/PseudoTerminal.h" @@ -41,6 +40,7 @@ #include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Target/Target.h" #include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/State.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/StringExtractor.h" #include "llvm/Support/Errno.h" @@ -245,13 +245,15 @@
[Lldb-commits] [lldb] r323340 - Remove unused includes from the Host module
Author: labath Date: Wed Jan 24 08:40:22 2018 New Revision: 323340 URL: http://llvm.org/viewvc/llvm-project?rev=323340&view=rev Log: Remove unused includes from the Host module Modified: lldb/trunk/source/Host/common/Symbols.cpp lldb/trunk/source/Host/freebsd/Host.cpp lldb/trunk/source/Host/macosx/Host.mm lldb/trunk/source/Host/macosx/Symbols.cpp lldb/trunk/source/Host/netbsd/Host.cpp lldb/trunk/source/Host/openbsd/Host.cpp Modified: lldb/trunk/source/Host/common/Symbols.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Symbols.cpp?rev=323340&r1=323339&r2=323340&view=diff == --- lldb/trunk/source/Host/common/Symbols.cpp (original) +++ lldb/trunk/source/Host/common/Symbols.cpp Wed Jan 24 08:40:22 2018 @@ -8,7 +8,6 @@ //===--===// #include "lldb/Host/Symbols.h" -#include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/Target.h" Modified: lldb/trunk/source/Host/freebsd/Host.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/freebsd/Host.cpp?rev=323340&r1=323339&r2=323340&view=diff == --- lldb/trunk/source/Host/freebsd/Host.cpp (original) +++ lldb/trunk/source/Host/freebsd/Host.cpp Wed Jan 24 08:40:22 2018 @@ -26,7 +26,6 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/Core/Module.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" Modified: lldb/trunk/source/Host/macosx/Host.mm URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=323340&r1=323339&r2=323340&view=diff == --- lldb/trunk/source/Host/macosx/Host.mm (original) +++ lldb/trunk/source/Host/macosx/Host.mm Wed Jan 24 08:40:22 2018 @@ -54,7 +54,6 @@ #include #include -#include "lldb/Core/Communication.h" #include "lldb/Host/ConnectionFileDescriptor.h" #include "lldb/Host/HostInfo.h" #include "lldb/Host/ThreadLauncher.h" Modified: lldb/trunk/source/Host/macosx/Symbols.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Symbols.cpp?rev=323340&r1=323339&r2=323340&view=diff == --- lldb/trunk/source/Host/macosx/Symbols.cpp (original) +++ lldb/trunk/source/Host/macosx/Symbols.cpp Wed Jan 24 08:40:22 2018 @@ -23,7 +23,6 @@ #include "Host/macosx/cfcpp/CFCData.h" #include "Host/macosx/cfcpp/CFCReleaser.h" #include "Host/macosx/cfcpp/CFCString.h" -#include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Host/Host.h" #include "lldb/Symbol/ObjectFile.h" Modified: lldb/trunk/source/Host/netbsd/Host.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/netbsd/Host.cpp?rev=323340&r1=323339&r2=323340&view=diff == --- lldb/trunk/source/Host/netbsd/Host.cpp (original) +++ lldb/trunk/source/Host/netbsd/Host.cpp Wed Jan 24 08:40:22 2018 @@ -25,7 +25,6 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/Core/Module.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" Modified: lldb/trunk/source/Host/openbsd/Host.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/openbsd/Host.cpp?rev=323340&r1=323339&r2=323340&view=diff == --- lldb/trunk/source/Host/openbsd/Host.cpp (original) +++ lldb/trunk/source/Host/openbsd/Host.cpp Wed Jan 24 08:40:22 2018 @@ -22,7 +22,6 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/Core/Module.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D42488: Remove ObjectFile usage from HostLinux::GetProcessInfo
clayborg accepted this revision. clayborg added a comment. This revision is now accepted and ready to land. Looks fine to me. https://reviews.llvm.org/D42488 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D42488: Remove ObjectFile usage from HostLinux::GetProcessInfo
davide accepted this revision. davide added a comment. Thanks for the spring cleaning! https://reviews.llvm.org/D42488 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D31451: New C++ function name parsing logic
clayborg added a comment. Herald added subscribers: llvm-commits, hintonda. This code is making debugging of large C++ apps so slow it is unusable... Repository: rL LLVM https://reviews.llvm.org/D31451 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D42195: [lldb] Generic base for testing gdb-remote behavior
owenpshaw updated this revision to Diff 131310. owenpshaw added a comment. - Updated condition for yaml2obj dependency, now based on LLDB_BUILT_STANDALONE - Find yaml2obj in the same directory as clang - Move yaml2obj code into lldbtest.py so it's available to all tests Is the findBuiltClang function the right thing to use here? I can't find anything else that uses it. https://reviews.llvm.org/D42195 Files: packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestGDBRemoteClient.py packages/Python/lldbsuite/test/functionalities/gdb_remote_client/a.yaml packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py packages/Python/lldbsuite/test/lldbtest.py test/CMakeLists.txt Index: test/CMakeLists.txt === --- test/CMakeLists.txt +++ test/CMakeLists.txt @@ -34,6 +34,10 @@ list(APPEND LLDB_TEST_DEPS lldb-mi) endif() +if(NOT LLDB_BUILT_STANDALONE) + list(APPEND LLDB_TEST_DEPS yaml2obj) +endif() + # The default architecture with which to compile test executables is the default LLVM target # architecture, which itself defaults to the host architecture. string(TOLOWER "${LLVM_TARGET_ARCH}" LLDB_DEFAULT_TEST_ARCH) Index: packages/Python/lldbsuite/test/lldbtest.py === --- packages/Python/lldbsuite/test/lldbtest.py +++ packages/Python/lldbsuite/test/lldbtest.py @@ -1604,6 +1604,31 @@ return os.environ["CC"] +def findYaml2obj(self): +""" +Get the path to the yaml2obj executable, which can be used to create +test object files from easy to write yaml instructions. + +Throws an Exception if the executable cannot be found. +""" +# Tries to find yaml2obj at the same folder as clang +clang_dir = os.path.dirname(self.findBuiltClang()) +path = os.path.join(clang_dir, "yaml2obj") +if os.path.exists(path): +return path +raise Exception("yaml2obj executable not found") + + +def yaml2obj(self, yaml_path, obj_path): +""" +Create an object file at the given path from a yaml file. + +Throws subprocess.CalledProcessError if the object could not be created. +""" +yaml2obj = self.findYaml2obj() +command = [yaml2obj, "-o=%s" % obj_path, yaml_path] +system([command]) + def getBuildFlags( self, use_cpp11=True, Index: packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py === --- /dev/null +++ packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py @@ -0,0 +1,442 @@ +import os +import os.path +import subprocess +import threading +import socket +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbtest_config + + +def checksum(message): +""" +Calculate the GDB server protocol checksum of the message. + +The GDB server protocol uses a simple modulo 256 sum. +""" +check = 0 +for c in message: +check += ord(c) +return check % 256 + + +def frame_packet(message): +""" +Create a framed packet that's ready to send over the GDB connection +channel. + +Framing includes surrounding the message between $ and #, and appending +a two character hex checksum. +""" +return "$%s#%02x" % (message, checksum(message)) + + +def escape_binary(message): +""" +Escape the binary message using the process described in the GDB server +protocol documentation. + +Most bytes are sent through as-is, but $, #, and { are escaped by writing +a { followed by the original byte mod 0x20. +""" +out = "" +for c in message: +d = ord(c) +if d in (0x23, 0x24, 0x7d): +out += chr(0x7d) +out += chr(d ^ 0x20) +else: +out += c +return out + + +def hex_encode_bytes(message): +""" +Encode the binary message by converting each byte into a two-character +hex string. +""" +out = "" +for c in message: +out += "%02x" % ord(c) +return out + + +def hex_decode_bytes(hex_bytes): +""" +Decode the hex string into a binary message by converting each two-character +hex string into a single output byte. +""" +out = "" +hex_len = len(hex_bytes) +while i < hex_len - 1: +out += chr(int(hex_bytes[i:i + 2]), 16) +i += 2 +return out + + +class MockGDBServerResponder: +""" +A base class for handing client packets and issuing server responses for +GDB tests. + +This handles many typical situations, while still allowing subclasses to +completely customize their responses. + +Most subclasses will be interested in overriding the other() method, which +handles any packet not recognized in the common packet handling
[Lldb-commits] [lldb] r323363 - www: update lldb architecture doc
Author: compnerd Date: Wed Jan 24 11:00:08 2018 New Revision: 323363 URL: http://llvm.org/viewvc/llvm-project?rev=323363&view=rev Log: www: update lldb architecture doc ArchSpec was moved from Core to Utility, so I modified the docs to reflect that. Patch by Alex Langford ! Modified: lldb/trunk/www/architecture/index.html Modified: lldb/trunk/www/architecture/index.html URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/www/architecture/index.html?rev=323363&r1=323362&r2=323363&view=diff == --- lldb/trunk/www/architecture/index.html (original) +++ lldb/trunk/www/architecture/index.html Wed Jan 24 11:00:08 2018 @@ -130,7 +130,6 @@ Address (section offset addressing) AddressRange - Architecture specification Broadcaster / Event / Listener Communication classes that use Connection objects Mangled names @@ -276,6 +275,7 @@ Abstract path manipulation (FileSpec) + Architecture specification Data buffers (DataBuffer, DataEncoder, DataExtractor) Logging Structured data manipulation (JSON) ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D42264: Update lldb architecture doc
xiaobai closed this revision. xiaobai added a subscriber: compnerd. xiaobai added a comment. @compnerd committed this for me! r323363 https://reviews.llvm.org/D42264 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D42488: Remove ObjectFile usage from HostLinux::GetProcessInfo
eugene added inline comments. Comment at: source/Host/linux/Host.cpp:129 + auto buffer_sp = DataBufferLLVM::CreateSliceFromPath(exe_path, 0x20, 0); + if (buffer_sp) +return ArchSpec(); Shouldn't it be ``` if (!buffer_sp) ``` ? https://reviews.llvm.org/D42488 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D42488: Remove ObjectFile usage from HostLinux::GetProcessInfo
labath planned changes to this revision. labath added inline comments. Comment at: source/Host/linux/Host.cpp:129 + auto buffer_sp = DataBufferLLVM::CreateSliceFromPath(exe_path, 0x20, 0); + if (buffer_sp) +return ArchSpec(); eugene wrote: > Shouldn't it be > > ``` > if (!buffer_sp) > ``` > > ? Indeed it should. Thanks. I'll have to figure out tomorrow why the test still passed... :/ https://reviews.llvm.org/D42488 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D31451: New C++ function name parsing logic
clayborg added a comment. This is part of the problem, but not the entire thing.. We had a mangled name: _ZNK3shk6detail17CallbackPublisherIZNS_5ThrowERKNSt15__exception_ptr13exception_ptrEEUlOT_E_E9SubscribeINS0_9ConcatMapINS0_18CallbackSubscriberIZNS_6GetAllIiNS1_IZZNS_9ConcatMapIZNS_6ConcatIJNS1_IZZNS_3MapIZZNS_7IfEmptyIS9_EEDaS7_ENKUlS6_E_clINS1_IZZNS_4TakeIiEESI_S7_ENKUlS6_E_clINS1_IZZNS_6FilterIZNS_9ElementAtEmEUlS7_E_EESI_S7_ENKUlS6_E_clINS1_IZZNSL_ImEESI_S7_ENKUlS6_E_clINS1_IZNS_4FromINS0_22InfiniteRangeContainerIiSI_S7_EUlS7_E_SI_S6_EUlS7_E_SI_S6_EUlS7_E_SI_S6_EUlS7_E_SI_S6_EUlS7_E_EESI_S7_ENKUlS6_E_clIS14_EESI_S6_EUlS7_E_EERNS1_IZZNSH_IS9_EESI_S7_ENKSK_IS14_EESI_S6_EUlS7_E0_ESI_DpOT_EUlS7_E_EESI_S7_ENKUlS6_E_clINS1_IZNS_5StartIJZNS_4JustIJS19_S1C_EEESI_S1F_EUlvE_ZNS1K_IJS19_S1C_EEESI_S1F_EUlvE0_EEESI_S1F_EUlS7_E_SI_S6_EUlS7_E_St6vectorIS6_SaIS6_EERKT0_NS_12ElementCountEbEUlS7_E_ZNSD_IiS1Q_EES1T_S1W_S1X_bEUlOS3_E_ZNSD_IiS1Q_EES1T_S1W_S1X_bEUlvE_EES1G_S1O_E25ConcatMapValuesSubscriberEEEDaS7_ It demangles to something that is 72MB in size!!! So yes, this code would take a while to parse all of that. So we need a way to deal with large C++ strings more effectively without having slow performance. Repository: rL LLVM https://reviews.llvm.org/D31451 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D31451: New C++ function name parsing logic
eugene added a comment. Greg, this name is amazing. My c++filt refuses to demangle it. We can probably give up on parsing C++ names if they're longer than 1000 characters or something. Repository: rL LLVM https://reviews.llvm.org/D31451 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D31451: New C++ function name parsing logic
clayborg added a comment. The funny thing is this is only 981 characters long... Not sure what the right cutoff would be... Repository: rL LLVM https://reviews.llvm.org/D31451 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D42277: Use test-specific module caches to avoid stale header conflicts
vsk added a comment. Is this OK to commit? https://reviews.llvm.org/D42277 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits