commit 6e1b36f62c0830978ab4db44f763e030cc74a18d (from 6cca9d0ee6a4676028e511e2c5384ed959b1816f) Merge: 6cca9d0ee6a4 0be0ab88a5d9 Author: Josh Stone Date: Tue Aug 9 16:33:52 2016 -0700 Merge pull request #147 from cuviper/attach-no-exe proccontrol: fix process attachment without an exe diff --git a/proccontrol/src/linux.C b/proccontrol/src/linux.C index 4502e357f79f..407a77ec6ecf 100644 --- a/proccontrol/src/linux.C +++ b/proccontrol/src/linux.C @@ -884,8 +884,9 @@ int linux_process::computeAddrWidth() * of name word will be 0x0 on 64 bit processes. On 32-bit process this * word will contain a value, of which some should be non-zero. * - * We'll thus check every word that is 1 mod 4. If all are 0x0 we assume we're - * looking at a 64-bit process. + * We'll thus check every word that is 1 mod 4 for little-endian machines, + * or 0 mod 4 for big-endian. If all words of either stripe are 0x0, we + * assume we're looking at a 64-bit process. **/ uint32_t buffer[256]; char auxv_name[64]; @@ -898,25 +899,21 @@ int linux_process::computeAddrWidth() return -1; } - long int result = read(fd, buffer, sizeof(buffer)); - long int words_read = result / sizeof(uint32_t); - int word_size = 8; + ssize_t result = read(fd, buffer, sizeof(buffer)); + ssize_t words_read = (result / sizeof(uint32_t)) & ~3; + close(fd); // We want to check the highest 4 bytes of each integer // On big-endian systems, these come first in memory - SymReader *objSymReader = getSymReader()->openSymbolReader(getExecutable()); - int start_index = objSymReader->isBigEndianDataEncoding() ? 0 : 1; - - for (long int i=start_index; illproc()->getSymReader()->openSymbolReader(proc_->llproc()->getExecutable()); abimajversion_ = abiminversion_ = 0; - objSymReader->getABIVersion(abimajversion_, abiminversion_); + auto exe = proc_->libraries().getExecutable(); + SymReader *objSymReader = proc_->llproc()->getSymReader()->openSymbolReader(exe->getName()); + if (objSymReader) + objSymReader->getABIVersion(abimajversion_, abiminversion_); if (!generateInt()) return false;