[336db295] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup taskdump
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[ffa2c8ef] | 35 | #include <async.h>
|
---|
[5baf209] | 36 | #include <elf/elf_linux.h>
|
---|
[336db295] | 37 | #include <stdio.h>
|
---|
| 38 | #include <stdlib.h>
|
---|
| 39 | #include <unistd.h>
|
---|
| 40 | #include <errno.h>
|
---|
| 41 | #include <udebug.h>
|
---|
| 42 | #include <task.h>
|
---|
[dafa2d04] | 43 | #include <as.h>
|
---|
[1ccafee] | 44 | #include <sys/types.h>
|
---|
| 45 | #include <sys/typefmt.h>
|
---|
[80487bc5] | 46 | #include <libarch/istate.h>
|
---|
[336db295] | 47 | #include <macros.h>
|
---|
| 48 | #include <assert.h>
|
---|
[3e6a98c5] | 49 | #include <stdbool.h>
|
---|
[336db295] | 50 |
|
---|
[3698e44] | 51 | #include <symtab.h>
|
---|
[dafa2d04] | 52 | #include <elf_core.h>
|
---|
[e515b21a] | 53 | #include <stacktrace.h>
|
---|
| 54 |
|
---|
[336db295] | 55 | #define LINE_BYTES 16
|
---|
| 56 |
|
---|
[79ae36dd] | 57 | static async_sess_t *sess;
|
---|
[336db295] | 58 | static task_id_t task_id;
|
---|
[dafa2d04] | 59 | static bool write_core_file;
|
---|
| 60 | static char *core_file_name;
|
---|
[3698e44] | 61 | static char *app_name;
|
---|
| 62 | static symtab_t *app_symtab;
|
---|
[336db295] | 63 |
|
---|
| 64 | static int connect_task(task_id_t task_id);
|
---|
| 65 | static int parse_args(int argc, char *argv[]);
|
---|
[e515b21a] | 66 | static void print_syntax(void);
|
---|
[336db295] | 67 | static int threads_dump(void);
|
---|
[80487bc5] | 68 | static int thread_dump(uintptr_t thash);
|
---|
[336db295] | 69 | static int areas_dump(void);
|
---|
[e515b21a] | 70 | static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value);
|
---|
[336db295] | 71 |
|
---|
[3698e44] | 72 | static void autoload_syms(void);
|
---|
| 73 | static char *get_app_task_name(void);
|
---|
| 74 | static char *fmt_sym_address(uintptr_t addr);
|
---|
| 75 |
|
---|
[5baf209] | 76 | static istate_t reg_state;
|
---|
| 77 |
|
---|
[336db295] | 78 | int main(int argc, char *argv[])
|
---|
| 79 | {
|
---|
| 80 | int rc;
|
---|
| 81 |
|
---|
| 82 | printf("Task Dump Utility\n");
|
---|
[dafa2d04] | 83 | write_core_file = false;
|
---|
[336db295] | 84 |
|
---|
| 85 | if (parse_args(argc, argv) < 0)
|
---|
| 86 | return 1;
|
---|
| 87 |
|
---|
| 88 | rc = connect_task(task_id);
|
---|
| 89 | if (rc < 0) {
|
---|
[7e752b2] | 90 | printf("Failed connecting to task %" PRIu64 ".\n", task_id);
|
---|
[336db295] | 91 | return 1;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[3698e44] | 94 | app_name = get_app_task_name();
|
---|
| 95 | app_symtab = NULL;
|
---|
| 96 |
|
---|
[7e752b2] | 97 | printf("Dumping task '%s' (task ID %" PRIu64 ").\n", app_name, task_id);
|
---|
[3698e44] | 98 | autoload_syms();
|
---|
| 99 | putchar('\n');
|
---|
[336db295] | 100 |
|
---|
| 101 | rc = threads_dump();
|
---|
| 102 | if (rc < 0)
|
---|
| 103 | printf("Failed dumping threads.\n");
|
---|
| 104 |
|
---|
| 105 | rc = areas_dump();
|
---|
| 106 | if (rc < 0)
|
---|
| 107 | printf("Failed dumping address space areas.\n");
|
---|
| 108 |
|
---|
[79ae36dd] | 109 | udebug_end(sess);
|
---|
| 110 | async_hangup(sess);
|
---|
[336db295] | 111 |
|
---|
| 112 | return 0;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | static int connect_task(task_id_t task_id)
|
---|
| 116 | {
|
---|
[79ae36dd] | 117 | async_sess_t *ksess = async_connect_kbox(task_id);
|
---|
| 118 |
|
---|
| 119 | if (!ksess) {
|
---|
| 120 | if (errno == ENOTSUP) {
|
---|
| 121 | printf("You do not have userspace debugging support "
|
---|
| 122 | "compiled in the kernel.\n");
|
---|
| 123 | printf("Compile kernel with 'Support for userspace debuggers' "
|
---|
| 124 | "(CONFIG_UDEBUG) enabled.\n");
|
---|
| 125 | return errno;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[336db295] | 128 | printf("Error connecting\n");
|
---|
[79ae36dd] | 129 | printf("async_connect_kbox(%" PRIu64 ") -> %d ", task_id, errno);
|
---|
| 130 | return errno;
|
---|
[336db295] | 131 | }
|
---|
[79ae36dd] | 132 |
|
---|
| 133 | int rc = udebug_begin(ksess);
|
---|
[336db295] | 134 | if (rc < 0) {
|
---|
| 135 | printf("udebug_begin() -> %d\n", rc);
|
---|
| 136 | return rc;
|
---|
| 137 | }
|
---|
[79ae36dd] | 138 |
|
---|
| 139 | sess = ksess;
|
---|
[336db295] | 140 | return 0;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | static int parse_args(int argc, char *argv[])
|
---|
| 144 | {
|
---|
| 145 | char *arg;
|
---|
| 146 | char *err_p;
|
---|
| 147 |
|
---|
| 148 | task_id = 0;
|
---|
| 149 |
|
---|
| 150 | --argc; ++argv;
|
---|
| 151 |
|
---|
| 152 | while (argc > 0) {
|
---|
| 153 | arg = *argv;
|
---|
| 154 | if (arg[0] == '-') {
|
---|
| 155 | if (arg[1] == 't' && arg[2] == '\0') {
|
---|
| 156 | /* Task ID */
|
---|
| 157 | --argc; ++argv;
|
---|
| 158 | task_id = strtol(*argv, &err_p, 10);
|
---|
| 159 | if (*err_p) {
|
---|
| 160 | printf("Task ID syntax error\n");
|
---|
| 161 | print_syntax();
|
---|
| 162 | return -1;
|
---|
| 163 | }
|
---|
[dafa2d04] | 164 | } else if (arg[1] == 'c' && arg[2] == '\0') {
|
---|
| 165 | write_core_file = true;
|
---|
| 166 |
|
---|
| 167 | --argc; ++argv;
|
---|
| 168 | core_file_name = *argv;
|
---|
[336db295] | 169 | } else {
|
---|
[7e752b2] | 170 | printf("Uknown option '%c'\n", arg[0]);
|
---|
[336db295] | 171 | print_syntax();
|
---|
| 172 | return -1;
|
---|
| 173 | }
|
---|
| 174 | } else {
|
---|
| 175 | break;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | --argc; ++argv;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | if (task_id == 0) {
|
---|
| 182 | printf("Missing task ID argument\n");
|
---|
| 183 | print_syntax();
|
---|
| 184 | return -1;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | if (argc != 0) {
|
---|
| 188 | printf("Extra arguments\n");
|
---|
| 189 | print_syntax();
|
---|
| 190 | return -1;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | return 0;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
[e515b21a] | 196 | static void print_syntax(void)
|
---|
[336db295] | 197 | {
|
---|
[dafa2d04] | 198 | printf("Syntax: taskdump [-c <core_file>] -t <task_id>\n");
|
---|
| 199 | printf("\t-c <core_file_id>\tName of core file to write.\n");
|
---|
[336db295] | 200 | printf("\t-t <task_id>\tWhich task to dump.\n");
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | static int threads_dump(void)
|
---|
| 204 | {
|
---|
| 205 | uintptr_t *thash_buf;
|
---|
| 206 | uintptr_t dummy_buf;
|
---|
| 207 | size_t buf_size, n_threads;
|
---|
| 208 |
|
---|
| 209 | size_t copied;
|
---|
| 210 | size_t needed;
|
---|
| 211 | size_t i;
|
---|
| 212 | int rc;
|
---|
| 213 |
|
---|
| 214 | /* TODO: See why NULL does not work. */
|
---|
[79ae36dd] | 215 | rc = udebug_thread_read(sess, &dummy_buf, 0, &copied, &needed);
|
---|
[336db295] | 216 | if (rc < 0) {
|
---|
| 217 | printf("udebug_thread_read() -> %d\n", rc);
|
---|
| 218 | return rc;
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | if (needed == 0) {
|
---|
| 222 | printf("No threads.\n\n");
|
---|
| 223 | return 0;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | buf_size = needed;
|
---|
| 227 | thash_buf = malloc(buf_size);
|
---|
| 228 |
|
---|
[79ae36dd] | 229 | rc = udebug_thread_read(sess, thash_buf, buf_size, &copied, &needed);
|
---|
[336db295] | 230 | if (rc < 0) {
|
---|
| 231 | printf("udebug_thread_read() -> %d\n", rc);
|
---|
| 232 | return rc;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | assert(copied == buf_size);
|
---|
| 236 | assert(needed == buf_size);
|
---|
| 237 |
|
---|
| 238 | n_threads = copied / sizeof(uintptr_t);
|
---|
| 239 |
|
---|
| 240 | printf("Threads:\n");
|
---|
| 241 | for (i = 0; i < n_threads; i++) {
|
---|
[7e752b2] | 242 | printf(" [%zu] hash: %p\n", 1 + i, (void *) thash_buf[i]);
|
---|
[80487bc5] | 243 |
|
---|
| 244 | thread_dump(thash_buf[i]);
|
---|
[336db295] | 245 | }
|
---|
| 246 | putchar('\n');
|
---|
| 247 |
|
---|
| 248 | free(thash_buf);
|
---|
| 249 |
|
---|
| 250 | return 0;
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | static int areas_dump(void)
|
---|
| 254 | {
|
---|
| 255 | as_area_info_t *ainfo_buf;
|
---|
| 256 | as_area_info_t dummy_buf;
|
---|
| 257 | size_t buf_size, n_areas;
|
---|
| 258 |
|
---|
| 259 | size_t copied;
|
---|
| 260 | size_t needed;
|
---|
| 261 | size_t i;
|
---|
| 262 | int rc;
|
---|
| 263 |
|
---|
[79ae36dd] | 264 | rc = udebug_areas_read(sess, &dummy_buf, 0, &copied, &needed);
|
---|
[336db295] | 265 | if (rc < 0) {
|
---|
| 266 | printf("udebug_areas_read() -> %d\n", rc);
|
---|
| 267 | return rc;
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | buf_size = needed;
|
---|
| 271 | ainfo_buf = malloc(buf_size);
|
---|
| 272 |
|
---|
[79ae36dd] | 273 | rc = udebug_areas_read(sess, ainfo_buf, buf_size, &copied, &needed);
|
---|
[336db295] | 274 | if (rc < 0) {
|
---|
| 275 | printf("udebug_areas_read() -> %d\n", rc);
|
---|
| 276 | return rc;
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | assert(copied == buf_size);
|
---|
| 280 | assert(needed == buf_size);
|
---|
| 281 |
|
---|
| 282 | n_areas = copied / sizeof(as_area_info_t);
|
---|
| 283 |
|
---|
| 284 | printf("Address space areas:\n");
|
---|
| 285 | for (i = 0; i < n_areas; i++) {
|
---|
[7e752b2] | 286 | printf(" [%zu] flags: %c%c%c%c base: %p size: %zu\n", 1 + i,
|
---|
[336db295] | 287 | (ainfo_buf[i].flags & AS_AREA_READ) ? 'R' : '-',
|
---|
| 288 | (ainfo_buf[i].flags & AS_AREA_WRITE) ? 'W' : '-',
|
---|
| 289 | (ainfo_buf[i].flags & AS_AREA_EXEC) ? 'X' : '-',
|
---|
| 290 | (ainfo_buf[i].flags & AS_AREA_CACHEABLE) ? 'C' : '-',
|
---|
[7e752b2] | 291 | (void *) ainfo_buf[i].start_addr, ainfo_buf[i].size);
|
---|
[336db295] | 292 | }
|
---|
| 293 |
|
---|
| 294 | putchar('\n');
|
---|
| 295 |
|
---|
[dafa2d04] | 296 | if (write_core_file) {
|
---|
| 297 | printf("Writing core file '%s'\n", core_file_name);
|
---|
[5baf209] | 298 |
|
---|
| 299 | rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess,
|
---|
| 300 | ®_state);
|
---|
| 301 |
|
---|
[dafa2d04] | 302 | if (rc != EOK) {
|
---|
| 303 | printf("Failed writing core file.\n");
|
---|
| 304 | return EIO;
|
---|
| 305 | }
|
---|
| 306 | }
|
---|
| 307 |
|
---|
[336db295] | 308 | free(ainfo_buf);
|
---|
| 309 |
|
---|
| 310 | return 0;
|
---|
| 311 | }
|
---|
| 312 |
|
---|
[80487bc5] | 313 | static int thread_dump(uintptr_t thash)
|
---|
| 314 | {
|
---|
| 315 | istate_t istate;
|
---|
[e515b21a] | 316 | uintptr_t pc, fp, nfp;
|
---|
| 317 | stacktrace_t st;
|
---|
[3698e44] | 318 | char *sym_pc;
|
---|
[80487bc5] | 319 | int rc;
|
---|
| 320 |
|
---|
[79ae36dd] | 321 | rc = udebug_regs_read(sess, thash, &istate);
|
---|
[80487bc5] | 322 | if (rc < 0) {
|
---|
| 323 | printf("Failed reading registers (%d).\n", rc);
|
---|
| 324 | return EIO;
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | pc = istate_get_pc(&istate);
|
---|
| 328 | fp = istate_get_fp(&istate);
|
---|
| 329 |
|
---|
[5baf209] | 330 | /* Save register state for dumping to core file later. */
|
---|
| 331 | reg_state = istate;
|
---|
| 332 |
|
---|
[196a1439] | 333 | sym_pc = fmt_sym_address(pc);
|
---|
[63594c0] | 334 | printf("Thread %p: PC = %s. FP = %p\n", (void *) thash,
|
---|
[7e752b2] | 335 | sym_pc, (void *) fp);
|
---|
[196a1439] | 336 | free(sym_pc);
|
---|
[e515b21a] | 337 |
|
---|
| 338 | st.op_arg = NULL;
|
---|
| 339 | st.read_uintptr = td_read_uintptr;
|
---|
| 340 |
|
---|
| 341 | while (stacktrace_fp_valid(&st, fp)) {
|
---|
[3698e44] | 342 | sym_pc = fmt_sym_address(pc);
|
---|
[7e752b2] | 343 | printf(" %p: %s\n", (void *) fp, sym_pc);
|
---|
[3698e44] | 344 | free(sym_pc);
|
---|
[e515b21a] | 345 |
|
---|
| 346 | rc = stacktrace_ra_get(&st, fp, &pc);
|
---|
| 347 | if (rc != EOK)
|
---|
| 348 | return rc;
|
---|
| 349 |
|
---|
| 350 | rc = stacktrace_fp_prev(&st, fp, &nfp);
|
---|
| 351 | if (rc != EOK)
|
---|
| 352 | return rc;
|
---|
| 353 |
|
---|
| 354 | fp = nfp;
|
---|
| 355 | }
|
---|
[80487bc5] | 356 |
|
---|
| 357 | return EOK;
|
---|
| 358 | }
|
---|
| 359 |
|
---|
[e515b21a] | 360 | static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value)
|
---|
| 361 | {
|
---|
| 362 | uintptr_t data;
|
---|
| 363 | int rc;
|
---|
| 364 |
|
---|
| 365 | (void) arg;
|
---|
| 366 |
|
---|
[79ae36dd] | 367 | rc = udebug_mem_read(sess, &data, addr, sizeof(data));
|
---|
[e515b21a] | 368 | if (rc < 0) {
|
---|
| 369 | printf("Warning: udebug_mem_read() failed.\n");
|
---|
| 370 | return rc;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | *value = data;
|
---|
| 374 | return EOK;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
[3698e44] | 377 | /** Attempt to find the right executable file and load the symbol table. */
|
---|
| 378 | static void autoload_syms(void)
|
---|
| 379 | {
|
---|
| 380 | char *file_name;
|
---|
| 381 | int rc;
|
---|
| 382 |
|
---|
| 383 | assert(app_name != NULL);
|
---|
| 384 | assert(app_symtab == NULL);
|
---|
| 385 |
|
---|
| 386 | rc = asprintf(&file_name, "/app/%s", app_name);
|
---|
| 387 | if (rc < 0) {
|
---|
| 388 | printf("Memory allocation failure.\n");
|
---|
| 389 | exit(1);
|
---|
| 390 | }
|
---|
| 391 |
|
---|
| 392 | rc = symtab_load(file_name, &app_symtab);
|
---|
| 393 | if (rc == EOK) {
|
---|
| 394 | printf("Loaded symbol table from %s\n", file_name);
|
---|
| 395 | free(file_name);
|
---|
| 396 | return;
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | free(file_name);
|
---|
| 400 |
|
---|
| 401 | rc = asprintf(&file_name, "/srv/%s", app_name);
|
---|
| 402 | if (rc < 0) {
|
---|
| 403 | printf("Memory allocation failure.\n");
|
---|
| 404 | exit(1);
|
---|
| 405 | }
|
---|
| 406 |
|
---|
[196a1439] | 407 | rc = symtab_load(file_name, &app_symtab);
|
---|
[3698e44] | 408 | if (rc == EOK) {
|
---|
| 409 | printf("Loaded symbol table from %s\n", file_name);
|
---|
| 410 | free(file_name);
|
---|
| 411 | return;
|
---|
| 412 | }
|
---|
| 413 |
|
---|
[6a343bdf] | 414 | rc = asprintf(&file_name, "/drv/%s/%s", app_name, app_name);
|
---|
| 415 | if (rc < 0) {
|
---|
| 416 | printf("Memory allocation failure.\n");
|
---|
| 417 | exit(1);
|
---|
| 418 | }
|
---|
| 419 |
|
---|
| 420 | rc = symtab_load(file_name, &app_symtab);
|
---|
| 421 | if (rc == EOK) {
|
---|
| 422 | printf("Loaded symbol table from %s\n", file_name);
|
---|
| 423 | free(file_name);
|
---|
| 424 | return;
|
---|
| 425 | }
|
---|
| 426 |
|
---|
[3698e44] | 427 | free(file_name);
|
---|
| 428 | printf("Failed autoloading symbol table.\n");
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 | static char *get_app_task_name(void)
|
---|
| 432 | {
|
---|
| 433 | char dummy_buf;
|
---|
| 434 | size_t copied, needed, name_size;
|
---|
| 435 | char *name;
|
---|
| 436 | int rc;
|
---|
| 437 |
|
---|
[79ae36dd] | 438 | rc = udebug_name_read(sess, &dummy_buf, 0, &copied, &needed);
|
---|
[3698e44] | 439 | if (rc < 0)
|
---|
| 440 | return NULL;
|
---|
| 441 |
|
---|
| 442 | name_size = needed;
|
---|
| 443 | name = malloc(name_size + 1);
|
---|
[79ae36dd] | 444 | rc = udebug_name_read(sess, name, name_size, &copied, &needed);
|
---|
[3698e44] | 445 | if (rc < 0) {
|
---|
| 446 | free(name);
|
---|
| 447 | return NULL;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | assert(copied == name_size);
|
---|
| 451 | assert(copied == needed);
|
---|
| 452 | name[copied] = '\0';
|
---|
| 453 |
|
---|
| 454 | return name;
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | /** Format address in symbolic form.
|
---|
| 458 | *
|
---|
| 459 | * Formats address as <symbol_name>+<offset> (<address>), if possible,
|
---|
| 460 | * otherwise as <address>.
|
---|
| 461 | *
|
---|
| 462 | * @param addr Address to format.
|
---|
| 463 | * @return Newly allocated string, address in symbolic form.
|
---|
| 464 | */
|
---|
| 465 | static char *fmt_sym_address(uintptr_t addr)
|
---|
| 466 | {
|
---|
| 467 | char *name;
|
---|
| 468 | size_t offs;
|
---|
| 469 | int rc;
|
---|
| 470 | char *str;
|
---|
| 471 |
|
---|
| 472 | if (app_symtab != NULL) {
|
---|
| 473 | rc = symtab_addr_to_name(app_symtab, addr, &name, &offs);
|
---|
| 474 | } else {
|
---|
| 475 | rc = ENOTSUP;
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | if (rc == EOK) {
|
---|
[7e752b2] | 479 | rc = asprintf(&str, "%p (%s+%zu)", (void *) addr, name, offs);
|
---|
[3698e44] | 480 | } else {
|
---|
[7e752b2] | 481 | rc = asprintf(&str, "%p", (void *) addr);
|
---|
[3698e44] | 482 | }
|
---|
| 483 |
|
---|
| 484 | if (rc < 0) {
|
---|
| 485 | printf("Memory allocation error.\n");
|
---|
| 486 | exit(1);
|
---|
| 487 | }
|
---|
| 488 |
|
---|
| 489 | return str;
|
---|
| 490 | }
|
---|
| 491 |
|
---|
[336db295] | 492 | /** @}
|
---|
| 493 | */
|
---|