<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, May 15, 2013 at 11:10 AM, Michael Sartain <span dir="ltr"><<a href="mailto:mikesart@valvesoftware.com" target="_blank">mikesart@valvesoftware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">On Wed, May 15, 2013 at 10:57 AM, Malea, Daniel <span dir="ltr"><<a href="mailto:daniel.malea@intel.com" target="_blank">daniel.malea@intel.com</a>></span> wrote:<br>
</div><div class="gmail_quote"><div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow:hidden">
I verified the implementation works as expected on Linux (Ubuntu 12.10), but I notice you're not filling in the process architecture. I believe there's an existing comment about why it's better to determine the arch in a different place, so it's probably fine to omit for now, but unless someone has any qualms, I will file a bug to also list the process' architectures when the user does "platform process list"; currently that field just shows "0".<br>
</div></blockquote></div><div><br><div class="gmail_extra">Ha! You are good. I'm actually about halfway through a
GetELFProcessCPUType() function right now. It looks like I have to
follow the exe link and read the elf header to get that data, but it's not too bad. Chris
Lattner was kinda enough to get me commit access, so hopefully I'll have
something for folks to review later today and then try to submit it myself if it looks ok.</div></div></div></blockquote></div><br></div><div class="gmail_extra">The new function is down below. Running "platform process list" results in something like this now:<br>
</div><div class="gmail_extra"><br>...<br>5919 5916 mikesart 6 x86_64-pc-linux tee<br>5920 5917 mikesart 6 x86_64-pc-linux tee<br>5923 1 mikesart 6 x86_64-pc-linux wineserver<br>5933 1 mikesart 6 x86_64-pc-linux wine64-preloader<br>
5939 1 mikesart 6 x86_64-pc-linux wine64-preloader<br>5947 1 mikesart 6 x86_64-pc-linux wine64-preloader<br>6004 1 mikesart 6 x86_64-pc-linux wine64-preloader<br>6049 1 mikesart 4 i386-pc-linux wine-preloader<br>
6181 2852 mikesart 6 x86_64-pc-linux dash<br><br></div><div class="gmail_extra">Please fire away with any feedback and if it looks ok I'll try to commit it later today.<br>Thanks much.<br></div><div class="gmail_extra">
-Mike<br></div><div class="gmail_extra"><br>static bool<br>GetELFProcessCPUType (const char *exe_path, ProcessInstanceInfo &process_info)<br>{<br> // First part of elf header structure copied from llvm/Support/ELF.h.<br>
// Read in just enough to get the machine type.<br> struct Elf_Ehdr<br> {<br> unsigned char e_ident[llvm::ELF::EI_NIDENT]; // ELF Identification bytes<br> uint16_t e_type; // Type of file (see ET_* below)<br>
uint16_t e_machine; // Required architecture for this file (see EM_*)<br><br> bool checkMagic() const {<br> return (memcmp(e_ident, llvm::ELF::ElfMagic, strlen(llvm::ELF::ElfMagic))) == 0;<br>
}<br> unsigned char getFileClass() const { return e_ident[llvm::ELF::EI_CLASS]; }<br> unsigned char getDataEncoding() const { return e_ident[llvm::ELF::EI_DATA]; }<br> } elfhdr;<br> bool success = false;<br>
<br> // Clear the architecture.<br> process_info.GetArchitecture().Clear();<br><br> // Open the binary and read the elf header.<br> int fd = open(exe_path, O_RDONLY, 0);<br> if (fd >= 0)<br> {<br> // Check that we read in enough bytes and the magic header lines up.<br>
int ret = read(fd, &elfhdr, sizeof(elfhdr));<br> if (ret == sizeof(elfhdr) && elfhdr.checkMagic())<br> {<br> // Check elf version.<br> int elfversion = elfhdr.e_ident[llvm::ELF::EI_VERSION];<br>
if (elfversion == llvm::ELF::EV_CURRENT)<br> {<br> // Check elf class.<br> int elfclass = elfhdr.getFileClass();<br> if (elfclass == llvm::ELF::ELFCLASS32 || elfclass == llvm::ELF::ELFCLASS64)<br>
{<br> // Check elf data encoding.<br> int elfdataencoding = elfhdr.getDataEncoding();<br> if (elfdataencoding == llvm::ELF::ELFDATA2LSB || elfdataencoding == llvm::ELF::ELFDATA2MSB)<br>
{<br> int byte_size = (elfclass == llvm::ELF::ELFCLASS32) ? 4 : 8;<br> lldb::ByteOrder byte_order = (elfdataencoding == llvm::ELF::ELFDATA2LSB) ? eByteOrderLittle : eByteOrderBig;<br>
lldb_private::DataExtractor data(&elfhdr, sizeof(elfhdr), byte_order, byte_size);<br><br> uint16_t cpu;<br> lldb::offset_t offset = offsetof(Elf_Ehdr, e_machine);<br>
if (data.GetU16 (&offset, &cpu, 1))<br> {<br> // Set the machine type.<br> process_info.GetArchitecture ().SetArchitecture (eArchTypeELF, cpu, LLDB_INVALID_CPUTYPE);<br>
// SetArchitecture() in ArchSpec.cpp sets vendor and os to unknown. Reset them to PC and Linux.<br> process_info.GetArchitecture ().GetTriple().setVendor (llvm::Triple::PC);<br>
process_info.GetArchitecture ().GetTriple().setOS (llvm::Triple::Linux);<br> success = true;<br> }<br> }<br> }<br>
}<br> }<br><br> close (fd);<br> }<br><br> return success;<br>}<br></div></div>