2 * See the dyninst/COPYRIGHT file for copyright information.
4 * We provide the Paradyn Tools (below described as "Paradyn")
5 * on an AS IS basis, and do not warrant its validity or performance.
6 * We reserve the right to update, modify, or discontinue this
7 * software at any time. We shall have no obligation to supply such
8 * updates or modifications or any other form of support to you.
10 * By your use of Paradyn, you understand and agree that we (or any
11 * other person or entity with proprietary rights in Paradyn) are
12 * under no obligation to provide either maintenance services,
13 * update services, notices of latent defects, or correction of
14 * defects for Paradyn.
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31 #include "SymtabReader.h"
32 #include "stackwalk/h/walker.h"
33 #include "stackwalk/h/framestepper.h"
34 #include "stackwalk/h/steppergroup.h"
35 #include "stackwalk/h/swk_errors.h"
36 #include "common/src/ntHeaders.h"
41 #include "stackwalk/h/procstate.h"
42 #include "stackwalk/h/frame.h"
44 #include "stackwalk/src/sw.h"
49 using namespace Dyninst;
50 using namespace Dyninst::Stackwalker;
52 bool Walker::createDefaultSteppers()
54 FrameStepper *stepper;
57 stepper = new FrameFuncStepper(this);
58 result = addStepper(stepper);
61 sw_printf("[%s:%u] - Stepper %p is FrameFuncStepper\n",
62 FILE__, __LINE__, stepper);
63 #if defined(USE_PARSE_API)
64 stepper = new AnalysisStepper(this);
65 result = addStepper(stepper);
72 sw_printf("[%s:%u] - Error adding stepper %p\n", stepper);
76 bool ProcSelf::getThreadIds(std::vector<THR_ID> &threads)
81 result = getDefaultThread(tid);
83 sw_printf("[%s:%u] - Could not read default thread\n",
88 threads.push_back(tid);
92 bool ProcSelf::getDefaultThread(THR_ID &default_tid)
94 default_tid = GetCurrentThread();
98 bool ProcSelf::readMem(void *dest, Address source, size_t size)
100 memcpy(dest, (const void *) source, size);
104 ProcSelf::ProcSelf(std::string exe_path) :
105 ProcessState(P_getpid(), exe_path)
109 void ProcSelf::initialize()
111 setDefaultLibraryTracker();
114 bool LibraryState::updateLibsArch(std::vector<std::pair<LibAddrPair, unsigned int> > &alibs)
119 SymbolReaderFactory* Stackwalker::getDefaultSymbolReader()
121 if (NULL == Walker::getSymbolReader()) {
122 static SymtabAPI::SymtabReaderFactory fact;
123 Walker::setSymbolReader(&fact);
125 return Walker::getSymbolReader();
128 static const char* START_FUNC_NAME = "_start";
129 static const char* CLONE_FUNC_NAME = "clone";
130 //static const char* START_THREAD_FUNC_NAME =
132 void BottomOfStackStepperImpl::initialize()
134 // For now, we stop when we get a return address of 0
135 ra_stack_tops.push_back(std::pair<Address, Address>(0, 0));
136 // By examination, this is an _start equivalent
137 ra_stack_tops.push_back(std::pair<Address, Address>(0x77959ECB, 0x77959F01));
138 ra_stack_tops.push_back(std::pair<Address, Address>(0x77959EAA, 0x77959EC6));
139 /* ProcessState *proc = walker->getProcessState();
142 sw_printf("[%s:%u] - Initializing BottomOfStackStepper\n", FILE__, __LINE__);
144 LibraryState *libs = proc->getLibraryTracker();
146 sw_printf("[%s:%u] - Error initing StackBottom. No library state for process.\n",
150 SymbolReaderFactory *fact = Walker::getSymbolReader();
152 sw_printf("[%s:%u] - Failed to get symbol reader\n");
158 LibAddrPair aout_addr;
159 SymReader *aout = NULL;
161 bool result = libs->getAOut(aout_addr);
163 aout = fact->openSymbolReader(aout_addr.first);
167 start_sym = aout->getSymbolByName(START_FUNC_NAME);
168 if (aout->isValidSymbol(start_sym)) {
169 Dyninst::Address start = aout->getSymbolOffset(start_sym)+aout_addr.second;
170 Dyninst::Address end = aout->getSymbolSize(start_sym) + start;
172 sw_printf("[%s:%u] - %s symbol has 0 length, using length of %lu\n",
173 FILE__, __LINE__, START_FUNC_NAME, START_HEURISTIC_LENGTH);
174 end = start + START_HEURISTIC_LENGTH;
176 sw_printf("[%s:%u] - Bottom stepper taking %lx to %lx for start\n",
177 FILE__, __LINE__, start, end);
178 ra_stack_tops.push_back(std::pair<Address, Address>(start, end));
185 LibAddrPair libthread_addr;
186 SymReader *libthread = NULL;
187 Symbol_t clone_sym, startthread_sym;
188 bool result = libs->getLibthread(libthread_addr);
190 libthread = fact->openSymbolReader(libthread_addr.first);
191 libthread_init = true;
194 clone_sym = libthread->getSymbolByName(CLONE_FUNC_NAME);
195 if (libthread->isValidSymbol(clone_sym)) {
196 Dyninst::Address start = libthread->getSymbolOffset(clone_sym) +
197 libthread_addr.second;
198 Dyninst::Address end = libthread->getSymbolSize(clone_sym) + start;
199 sw_printf("[%s:%u] - Bottom stepper taking %lx to %lx for clone\n",
200 FILE__, __LINE__, start, end);
201 ra_stack_tops.push_back(std::pair<Address, Address>(start, end));
203 startthread_sym = libthread->getSymbolByName(START_THREAD_FUNC_NAME);
204 if (libthread->isValidSymbol(startthread_sym)) {
205 Dyninst::Address start = libthread->getSymbolOffset(startthread_sym) +
206 libthread_addr.second;
207 Dyninst::Address end = libthread->getSymbolSize(startthread_sym) + start;
208 sw_printf("[%s:%u] - Bottom stepper taking %lx to %lx for start_thread\n",
209 FILE__, __LINE__, start, end);
210 ra_stack_tops.push_back(std::pair<Address, Address>(start, end));
216 void BottomOfStackStepperImpl::newLibraryNotification(LibAddrPair *, lib_change_t)