1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. */
6 /* XRay -- a simple profiler for Native Client */
13 #include "xray/xray_priv.h"
17 struct XRaySymbol* XRaySymbolTableCreateEntry(struct XRaySymbolTable* symtab,
21 char symbol_text[XRAY_LINE_SIZE];
24 if (2 != sscanf(line, "%x %1023s", &uiaddr, symbol_text))
26 if (uiaddr > 0x07FFFFFF) {
27 fprintf(stderr, "While parsing the mapfile, XRay encountered:\n");
28 fprintf(stderr, "%s\n", line);
30 "XRay only works with code addresses 0x00000000 - 0x07FFFFFF\n");
31 fprintf(stderr, "All functions must reside in this address space.\n");
34 addr = (uint32_t)uiaddr;
35 parsed_symbol = strstr(line, symbol_text);
36 newln = strstr(parsed_symbol, "\n");
40 return XRaySymbolTableAddByName(symtab, parsed_symbol, addr);
44 void XRaySymbolTableParseMapfile(struct XRaySymbolTable* symtab,
45 const char* mapfile) {
47 char line[XRAY_LINE_SIZE];
49 bool in_link_once = false;
50 int in_link_once_counter = 0;
53 printf("XRay: opening mapfile %s\n", mapfile);
54 f = fopen(mapfile, "rt");
56 fprintf(stderr, "XRay: failed to open %s\n", mapfile);
59 printf("XRay: parsing...\n");
60 while (NULL != fgets(line, XRAY_LINE_SIZE, f)) {
61 if (line == strstr(line, " .text ")) {
65 if (line == strstr(line, " .gnu.linkonce.t.")) {
67 in_link_once_counter = 0;
70 if (line == strstr(line, " .text.")) {
72 in_link_once_counter = 0;
75 if (line == strstr(line, " 0x")) {
77 XRaySymbolTableCreateEntry(symtab, line);
79 } else if (in_link_once) {
80 if (in_link_once_counter != 0) {
81 if (NULL != XRaySymbolTableCreateEntry(symtab, line))
84 ++in_link_once_counter;
93 printf("XRay: parsed %d symbols into symbol table\n", num_symbols);