def do_POST(self): LogTrace("Received request: " + self.path + " on thread " + threading.currentThread().getName()) try: length = int(self.headers["Content-Length"]) # Read in the request body without blocking self.connection.settimeout(SOCKET_READ_TIMEOUT) requestBody = self.rfile.read(length) # Put the connection back into blocking mode so rfile/wfile can be used safely self.connection.settimeout(None) if len(requestBody) < length: # This could be a broken connection, writing an error message into it could be a bad idea # See http://bugs.python.org/issue14574 LogTrace("Read " + str(len(requestBody)) + " bytes but Content-Length is " + str(length)) return LogTrace("Request body: " + requestBody) rawRequest = json.loads(requestBody) request = SymbolicationRequest(gSymFileManager, rawRequest) if not request.isValidRequest: LogTrace("Unable to parse request") self.sendHeaders(400) return except Exception as e: LogTrace("Unable to parse request body: " + str(e)) # Ensure connection is back in blocking mode so rfile/wfile can be used safely self.connection.settimeout(None) self.sendHeaders(400) return try: self.sendHeaders(200) response = {'symbolicatedStacks': []} for stackIndex in range(len(request.stacks)): symbolicatedStack = request.Symbolicate(stackIndex) # Free up memory ASAP request.stacks[stackIndex] = [] response['symbolicatedStacks'].append(symbolicatedStack) response['knownModules'] = request.knownModules[:] if not request.includeKnownModulesInResponse: response = response['symbolicatedStacks'] request.Reset() LogTrace("Response: " + json.dumps(response)) self.wfile.write(json.dumps(response)) except Exception as e: LogTrace("Exception in do_POST: " + str(e))
def _resolve_symbols(self, symbols_to_resolve): memoryMap = [] processedStack = [] all_symbols = [] for moduleIndex, library_with_symbols in enumerate(symbols_to_resolve): lib = library_with_symbols["library"] symbols = library_with_symbols["symbols"] memoryMap.append(self._module_from_lib(lib)) all_symbols += symbols for symbol in symbols: processedStack.append([moduleIndex, int(symbol, 0) - lib["start"]]) rawRequest = { "stacks": [processedStack], "memoryMap": memoryMap, "version": 4, "symbolSources": ["FIREFOX", "WINDOWS"] } request = SymbolicationRequest(self.sym_file_manager, rawRequest) if not request.isValidRequest: print "invalid request" return {} symbolicated_stack = request.Symbolicate(0) return dict(zip(all_symbols, symbolicated_stack))
def get_unknown_modules_in_profile(self, profile_json): if "libs" not in profile_json: return [] shared_libraries = json.loads(profile_json["libs"]) memoryMap = [] for lib in shared_libraries: memoryMap.append(self._module_from_lib(lib)) rawRequest = { "stacks": [[]], "memoryMap": memoryMap, "version": 4, "symbolSources": ["FIREFOX", "WINDOWS"] } request = SymbolicationRequest(self.sym_file_manager, rawRequest) if not request.isValidRequest: return [] request.Symbolicate(0) # This sets request.knownModules unknown_modules = [] for i, lib in enumerate(shared_libraries): if not request.knownModules[i]: unknown_modules.append(lib) return unknown_modules
def processSymbolicationRequest(rawRequest, remoteIp): decodedRequest = json.loads(rawRequest) request = SymbolicationRequest(gSymFileManager, decodedRequest, remoteIp) if not request.isValidRequest: LogDebug("Unable to parse request", remoteIp) return None response = { 'symbolicatedStacks': [] } for stackIndex in range(len(request.stacks)): symbolicatedStack = request.Symbolicate(stackIndex) # Free up memory ASAP request.stacks[stackIndex] = [] response['symbolicatedStacks'].append(symbolicatedStack) response['knownModules'] = request.knownModules[:] if not request.includeKnownModulesInResponse: response = response['symbolicatedStacks'] request.Reset() return json.dumps(response)
def find_symbol(lib_name, offset): rawRequest = { "stacks": [[[0, int(offset, 0)]]], "memoryMap": [moduleDict[lib_name]], "version": 3, "osName": "Windows", "appName": "Firefox" } request = SymbolicationRequest(symbolicator.sym_file_manager, rawRequest) symbolicated_stack = request.Symbolicate(0) return symbolicated_stack[0]