[Lldb-commits] [lldb] r182065 - Implement ObjectFileELF::GetModuleSpecifications(), and add PlatformLinux code to deal with unknown arch properties.

Mike Sartain mikesart at valvesoftware.com
Thu May 16 18:23:12 PDT 2013


Somehow having the architecture set on Linux is messing up the print str.c_str() call somewhere. Egads.

I'll revert this and debug it locally. Sorry. I'll be sure to run all these tests here before submitting next time as well...
 -Mike

mikesart at mikesart-rad:~/data/src/llvm/llvm/tools/lldb/test/expression_command/call-function$ $lldb_build/bin/lldb --debug a.out
Current executable set to 'a.out' (x86_64).
(lldb) breakpoint set -f "main.cpp" -l 13
Breakpoint 1: where = a.out`main + 184 at main.cpp:13, address = 0x0000000000400c38
(lldb) run
Process 26014 launched: '/home/mikesart/data/src/llvm/llvm/tools/lldb/test/expression_command/call-function/a.out' (x86_64)
Hello world
Hello world
Process 26014 stopped
* thread #1: tid = 0x659e, 0x0000000000400c38 a.out`main(argc=1, argv=0x00007fff271f4778) + 184 at main.cpp:13, stop reason = breakpoint 1.1
    frame #0: 0x0000000000400c38 a.out`main(argc=1, argv=0x00007fff271f4778) + 184 at main.cpp:13
   10       print str
   11       print str.c_str()
   12   #endif
-> 13       return 0; // Please test these expressions while stopped at this line:
   14   }
(lldb) print str
(std::string) $0 = "Hello world"
(lldb) print str.c_str()
error: call to a function 'std::string::c_str() const' ('_ZNKSs5c_strEv') that is not present in the target
error: The expression could not be prepared to run in the target
(lldb) 

It's supposed to do this:

(lldb) print str.c_str()
(const char *) $1 = 0x0000000001c94028 "Hello world"

________________________________________
From: Malea, Daniel [daniel.malea at intel.com]
Sent: Thursday, May 16, 2013 5:38 PM
To: Mike Sartain; lldb-commits at cs.uiuc.edu
Subject: Re: [Lldb-commits] [lldb] r182065 - Implement ObjectFileELF::GetModuleSpecifications(), and add PlatformLinux code to deal with unknown arch properties.

Hey Mike, this commit seems to have caused some issues (at first glance,
related to expression evaluation) on the clang buildbot:

http://lab.llvm.org:8011/builders/lldb-x86_64-debian-clang/builds/3349

Can you take a look?

(BTW, if you're using cmake to build, you can run "[make|ninja]
check-lldb" to run the entire suite, otherwise for the configure build
it's "make -C tools/lldb/test" IIRC)

Thanks,
Dan

On 2013-05-16 8:20 PM, "Michael Sartain" <mikesart at valvesoftware.com>
wrote:

>Author: mikesart
>Date: Thu May 16 19:20:21 2013
>New Revision: 182065
>
>URL: http://llvm.org/viewvc/llvm-project?rev=182065&view=rev
>Log:
>Implement ObjectFileELF::GetModuleSpecifications(), and add PlatformLinux
>code to deal with unknown arch properties.
>
>CR: Greg Clayton
>
>
>Modified:
>    lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
>    lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
>    lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
>
>Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
>URL:
>http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/E
>LF/ObjectFileELF.cpp?rev=182065&r1=182064&r2=182065&view=diff
>==========================================================================
>====
>--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
>+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Thu May 16
>19:20:21 2013
>@@ -222,6 +222,18 @@ ObjectFileELF::CreateMemoryInstance (con
>     return NULL;
> }
>
>+bool
>+ObjectFileELF::MagicBytesMatch (DataBufferSP& data_sp,
>+                                  lldb::addr_t data_offset,
>+                                  lldb::addr_t data_length)
>+{
>+    if (data_sp && data_sp->GetByteSize() > (llvm::ELF::EI_NIDENT +
>data_offset))
>+    {
>+        const uint8_t *magic = data_sp->GetBytes() + data_offset;
>+        return ELFHeader::MagicBytesMatch(magic);
>+    }
>+    return false;
>+}
>
> size_t
> ObjectFileELF::GetModuleSpecifications (const lldb_private::FileSpec&
>file,
>@@ -231,7 +243,33 @@ ObjectFileELF::GetModuleSpecifications (
>                                         lldb::offset_t length,
>                                         lldb_private::ModuleSpecList
>&specs)
> {
>-    return 0;
>+    const size_t initial_count = specs.GetSize();
>+
>+    if (ObjectFileELF::MagicBytesMatch(data_sp, 0,
>data_sp->GetByteSize()))
>+    {
>+        DataExtractor data;
>+        data.SetData(data_sp);
>+        elf::ELFHeader header;
>+        if (header.Parse(data, &data_offset))
>+        {
>+            if (data_sp)
>+            {
>+                ModuleSpec spec;
>+                spec.GetFileSpec() = file;
>+                spec.GetArchitecture().SetArchitecture(eArchTypeELF,
>+                                                       header.e_machine,
>+
>LLDB_INVALID_CPUTYPE);
>+                if (spec.GetArchitecture().IsValid())
>+                {
>+                    // ObjectFileMachO adds the UUID here also, but that
>isn't in the elf header
>+                    // so we'd have to read the entire file in and
>calculate the md5sum.
>+                    // That'd be bad for this routine...
>+                    specs.Append(spec);
>+                }
>+            }
>+        }
>+    }
>+    return specs.GetSize() - initial_count;
> }
>
> //------------------------------------------------------------------
>
>Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
>URL:
>http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/E
>LF/ObjectFileELF.h?rev=182065&r1=182064&r2=182065&view=diff
>==========================================================================
>====
>--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h (original)
>+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h Thu May 16
>19:20:21 2013
>@@ -65,6 +65,12 @@ public:
>                              lldb::offset_t file_offset,
>                              lldb::offset_t length,
>                              lldb_private::ModuleSpecList &specs);
>+
>+    static bool
>+    MagicBytesMatch (lldb::DataBufferSP& data_sp,
>+                     lldb::addr_t offset,
>+                     lldb::addr_t length);
>+
>     //------------------------------------------------------------------
>     // PluginInterface protocol
>     //------------------------------------------------------------------
>
>Modified: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
>URL:
>http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Lin
>ux/PlatformLinux.cpp?rev=182065&r1=182064&r2=182065&view=diff
>==========================================================================
>====
>--- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp (original)
>+++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp Thu May 16
>19:20:21 2013
>@@ -208,6 +208,29 @@ PlatformLinux::ResolveExecutable (const
>                                                  NULL,
>                                                  NULL,
>                                                  NULL);
>+            if (error.Fail())
>+            {
>+                // If we failed, it may be because the vendor and os
>aren't known. If that is the
>+                // case, try setting them to the host architecture and
>give it another try.
>+                llvm::Triple &module_triple =
>module_spec.GetArchitecture().GetTriple();
>+                bool is_vendor_specified = (module_triple.getVendor() !=
>llvm::Triple::UnknownVendor);
>+                bool is_os_specified = (module_triple.getOS() !=
>llvm::Triple::UnknownOS);
>+                if (!is_vendor_specified || !is_os_specified)
>+                {
>+                    const llvm::Triple &host_triple =
>Host::GetArchitecture (Host::eSystemDefaultArchitecture).GetTriple();
>+
>+                    if (!is_vendor_specified)
>+                        module_triple.setVendorName
>(host_triple.getVendorName());
>+                    if (!is_os_specified)
>+                        module_triple.setOSName
>(host_triple.getOSName());
>+
>+                    error = ModuleList::GetSharedModule (module_spec,
>+                                                         exe_module_sp,
>+                                                         NULL,
>+                                                         NULL,
>+                                                         NULL);
>+                }
>+            }
>
>             // TODO find out why exe_module_sp might be NULL
>             if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL)
>
>
>_______________________________________________
>lldb-commits mailing list
>lldb-commits at cs.uiuc.edu
>http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits





More information about the lldb-commits mailing list