13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 11 ■ TRACKING DOWN BUGSmemcpy(0x61a6d0, "subversion_repos.html", 22) = 0x61a6d0readdir(0x61ddf0)= 0x61e510memset(0x629e20, '\000', 184)= 0x629e20strlen("mono-samples.png") = 16malloc(17)= 0x61a6f0memcpy(0x61a6f0, "mono-samples.png", 17) = 0x61a6f0readdir(0x61ddf0)= 0x61e538memset(0x629ed8, '\000', 184)= 0x629ed8■ Note As with system calls, library calls are also well documented in <strong>Linux</strong> systems. man memcpy will, forexample, give you information on the memcpy library call.Looking at the output here, the first line is a call to memcpy. This is copying 22 bytes from the memoryaddress containing the string subversion_repos.html to the memory address 0x61a6d0. As with strace,ltrace will dereference certain pointers for you. In this case, instead of giving the pointer to the memoryaddress for the source of the data, it dereferences it to give you the string that’s stored at that address(here it’s subversion_repos.html, which is the name of one of the files that ls is listing). The return valueis just the destination memory address.readdir, on the next line, is a function that returns a pointer to the next directory entry. Theargument (here 0x61ddf0) is a pointer to the directory itself, and the return value is where to look for thenext entry. memset writes a given number (here 184) of bytes of a particular value (here \000) to the stringreferenced by the memory pointer (0x629e20).strlen gives the length of its argument string. Here, it’s the next directory entry (as returned byreaddir), and again, ltrace dereferences the pointer for you to give you the string value instead ratherthan just a memory address. The next line uses a malloc call to deal with memory allocation, setting upsufficient memory (the string length plus one byte) to hold the next directory entry. Then the wholeseries starts over again with memcpy and the next directory entry.Most of the time you probably won’t need to use ltrace to this level of detail, but this shouldprovide you with enough of a guide to be able to use the man pages as a reference to decipher the ltraceoutput for a program that’s causing you problems.■ Note You can also use ldd to check which shared libraries a particular program requires. If a particular librarycan’t be found, ldd will report this.11-5a. Setting ltrace OptionsHere are the ltrace options:• -f: Traces child processes (forks) as they’re created.• -t, -tt, -ttt: Puts the time of day at the start of each line, given to the second,microsecond, or second+microsecond and written as seconds-since-epoch.222Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!