| 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 |
|
|---|
| 35 | #include <async.h>
|
|---|
| 36 | #include <stdio.h>
|
|---|
| 37 | #include <stdlib.h>
|
|---|
| 38 | #include <unistd.h>
|
|---|
| 39 | #include <errno.h>
|
|---|
| 40 | #include <udebug.h>
|
|---|
| 41 | #include <task.h>
|
|---|
| 42 | #include <as.h>
|
|---|
| 43 | #include <sys/types.h>
|
|---|
| 44 | #include <sys/typefmt.h>
|
|---|
| 45 | #include <libarch/istate.h>
|
|---|
| 46 | #include <macros.h>
|
|---|
| 47 | #include <assert.h>
|
|---|
| 48 | #include <bool.h>
|
|---|
| 49 |
|
|---|
| 50 | #include <symtab.h>
|
|---|
| 51 | #include <elf_core.h>
|
|---|
| 52 | #include <stacktrace.h>
|
|---|
| 53 |
|
|---|
| 54 | #define LINE_BYTES 16
|
|---|
| 55 |
|
|---|
| 56 | static int phoneid;
|
|---|
| 57 | static task_id_t task_id;
|
|---|
| 58 | static bool write_core_file;
|
|---|
| 59 | static char *core_file_name;
|
|---|
| 60 | static char *app_name;
|
|---|
| 61 | static symtab_t *app_symtab;
|
|---|
| 62 |
|
|---|
| 63 | static int connect_task(task_id_t task_id);
|
|---|
| 64 | static int parse_args(int argc, char *argv[]);
|
|---|
| 65 | static void print_syntax(void);
|
|---|
| 66 | static int threads_dump(void);
|
|---|
| 67 | static int thread_dump(uintptr_t thash);
|
|---|
| 68 | static int areas_dump(void);
|
|---|
| 69 | static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value);
|
|---|
| 70 |
|
|---|
| 71 | static void autoload_syms(void);
|
|---|
| 72 | static char *get_app_task_name(void);
|
|---|
| 73 | static char *fmt_sym_address(uintptr_t addr);
|
|---|
| 74 |
|
|---|
| 75 | int main(int argc, char *argv[])
|
|---|
| 76 | {
|
|---|
| 77 | int rc;
|
|---|
| 78 |
|
|---|
| 79 | printf("Task Dump Utility\n");
|
|---|
| 80 | write_core_file = false;
|
|---|
| 81 |
|
|---|
| 82 | if (parse_args(argc, argv) < 0)
|
|---|
| 83 | return 1;
|
|---|
| 84 |
|
|---|
| 85 | rc = connect_task(task_id);
|
|---|
| 86 | if (rc < 0) {
|
|---|
| 87 | printf("Failed connecting to task %" PRIu64 ".\n", task_id);
|
|---|
| 88 | return 1;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | app_name = get_app_task_name();
|
|---|
| 92 | app_symtab = NULL;
|
|---|
| 93 |
|
|---|
| 94 | printf("Dumping task '%s' (task ID %" PRIu64 ").\n", app_name, task_id);
|
|---|
| 95 | autoload_syms();
|
|---|
| 96 | putchar('\n');
|
|---|
| 97 |
|
|---|
| 98 | rc = threads_dump();
|
|---|
| 99 | if (rc < 0)
|
|---|
| 100 | printf("Failed dumping threads.\n");
|
|---|
| 101 |
|
|---|
| 102 | rc = areas_dump();
|
|---|
| 103 | if (rc < 0)
|
|---|
| 104 | printf("Failed dumping address space areas.\n");
|
|---|
| 105 |
|
|---|
| 106 | udebug_end(phoneid);
|
|---|
| 107 | async_hangup(phoneid);
|
|---|
| 108 |
|
|---|
| 109 | return 0;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | static int connect_task(task_id_t task_id)
|
|---|
| 113 | {
|
|---|
| 114 | int rc;
|
|---|
| 115 |
|
|---|
| 116 | rc = async_connect_kbox(task_id);
|
|---|
| 117 |
|
|---|
| 118 | if (rc == ENOTSUP) {
|
|---|
| 119 | printf("You do not have userspace debugging support "
|
|---|
| 120 | "compiled in the kernel.\n");
|
|---|
| 121 | printf("Compile kernel with 'Support for userspace debuggers' "
|
|---|
| 122 | "(CONFIG_UDEBUG) enabled.\n");
|
|---|
| 123 | return rc;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | if (rc < 0) {
|
|---|
| 127 | printf("Error connecting\n");
|
|---|
| 128 | printf("async_connect_kbox(%" PRIu64 ") -> %d ", task_id, rc);
|
|---|
| 129 | return rc;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | phoneid = rc;
|
|---|
| 133 |
|
|---|
| 134 | rc = udebug_begin(phoneid);
|
|---|
| 135 | if (rc < 0) {
|
|---|
| 136 | printf("udebug_begin() -> %d\n", rc);
|
|---|
| 137 | return rc;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 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 | }
|
|---|
| 164 | } else if (arg[1] == 'c' && arg[2] == '\0') {
|
|---|
| 165 | write_core_file = true;
|
|---|
| 166 |
|
|---|
| 167 | --argc; ++argv;
|
|---|
| 168 | core_file_name = *argv;
|
|---|
| 169 | } else {
|
|---|
| 170 | printf("Uknown option '%c'\n", arg[0]);
|
|---|
| 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 |
|
|---|
| 196 | static void print_syntax(void)
|
|---|
| 197 | {
|
|---|
| 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");
|
|---|
| 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. */
|
|---|
| 215 | rc = udebug_thread_read(phoneid, &dummy_buf, 0, &copied, &needed);
|
|---|
| 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 |
|
|---|
| 229 | rc = udebug_thread_read(phoneid, thash_buf, buf_size, &copied, &needed);
|
|---|
| 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++) {
|
|---|
| 242 | printf(" [%zu] hash: %p\n", 1 + i, (void *) thash_buf[i]);
|
|---|
| 243 |
|
|---|
| 244 | thread_dump(thash_buf[i]);
|
|---|
| 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 |
|
|---|
| 264 | rc = udebug_areas_read(phoneid, &dummy_buf, 0, &copied, &needed);
|
|---|
| 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 |
|
|---|
| 273 | rc = udebug_areas_read(phoneid, ainfo_buf, buf_size, &copied, &needed);
|
|---|
| 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++) {
|
|---|
| 286 | printf(" [%zu] flags: %c%c%c%c base: %p size: %zu\n", 1 + i,
|
|---|
| 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' : '-',
|
|---|
| 291 | (void *) ainfo_buf[i].start_addr, ainfo_buf[i].size);
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | putchar('\n');
|
|---|
| 295 |
|
|---|
| 296 | if (write_core_file) {
|
|---|
| 297 | printf("Writing core file '%s'\n", core_file_name);
|
|---|
| 298 | rc = elf_core_save(core_file_name, ainfo_buf, n_areas, phoneid);
|
|---|
| 299 | if (rc != EOK) {
|
|---|
| 300 | printf("Failed writing core file.\n");
|
|---|
| 301 | return EIO;
|
|---|
| 302 | }
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | free(ainfo_buf);
|
|---|
| 306 |
|
|---|
| 307 | return 0;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | static int thread_dump(uintptr_t thash)
|
|---|
| 311 | {
|
|---|
| 312 | istate_t istate;
|
|---|
| 313 | uintptr_t pc, fp, nfp;
|
|---|
| 314 | stacktrace_t st;
|
|---|
| 315 | char *sym_pc;
|
|---|
| 316 | int rc;
|
|---|
| 317 |
|
|---|
| 318 | rc = udebug_regs_read(phoneid, thash, &istate);
|
|---|
| 319 | if (rc < 0) {
|
|---|
| 320 | printf("Failed reading registers (%d).\n", rc);
|
|---|
| 321 | return EIO;
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | pc = istate_get_pc(&istate);
|
|---|
| 325 | fp = istate_get_fp(&istate);
|
|---|
| 326 |
|
|---|
| 327 | sym_pc = fmt_sym_address(pc);
|
|---|
| 328 | printf("Thread %p: PC = %s. FP = %p\n", (void *) thash,
|
|---|
| 329 | sym_pc, (void *) fp);
|
|---|
| 330 | free(sym_pc);
|
|---|
| 331 |
|
|---|
| 332 | st.op_arg = NULL;
|
|---|
| 333 | st.read_uintptr = td_read_uintptr;
|
|---|
| 334 |
|
|---|
| 335 | while (stacktrace_fp_valid(&st, fp)) {
|
|---|
| 336 | sym_pc = fmt_sym_address(pc);
|
|---|
| 337 | printf(" %p: %s\n", (void *) fp, sym_pc);
|
|---|
| 338 | free(sym_pc);
|
|---|
| 339 |
|
|---|
| 340 | rc = stacktrace_ra_get(&st, fp, &pc);
|
|---|
| 341 | if (rc != EOK)
|
|---|
| 342 | return rc;
|
|---|
| 343 |
|
|---|
| 344 | rc = stacktrace_fp_prev(&st, fp, &nfp);
|
|---|
| 345 | if (rc != EOK)
|
|---|
| 346 | return rc;
|
|---|
| 347 |
|
|---|
| 348 | fp = nfp;
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | return EOK;
|
|---|
| 352 | }
|
|---|
| 353 |
|
|---|
| 354 | static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value)
|
|---|
| 355 | {
|
|---|
| 356 | uintptr_t data;
|
|---|
| 357 | int rc;
|
|---|
| 358 |
|
|---|
| 359 | (void) arg;
|
|---|
| 360 |
|
|---|
| 361 | rc = udebug_mem_read(phoneid, &data, addr, sizeof(data));
|
|---|
| 362 | if (rc < 0) {
|
|---|
| 363 | printf("Warning: udebug_mem_read() failed.\n");
|
|---|
| 364 | return rc;
|
|---|
| 365 | }
|
|---|
| 366 |
|
|---|
| 367 | *value = data;
|
|---|
| 368 | return EOK;
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 | /** Attempt to find the right executable file and load the symbol table. */
|
|---|
| 372 | static void autoload_syms(void)
|
|---|
| 373 | {
|
|---|
| 374 | char *file_name;
|
|---|
| 375 | int rc;
|
|---|
| 376 |
|
|---|
| 377 | assert(app_name != NULL);
|
|---|
| 378 | assert(app_symtab == NULL);
|
|---|
| 379 |
|
|---|
| 380 | rc = asprintf(&file_name, "/app/%s", app_name);
|
|---|
| 381 | if (rc < 0) {
|
|---|
| 382 | printf("Memory allocation failure.\n");
|
|---|
| 383 | exit(1);
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 | rc = symtab_load(file_name, &app_symtab);
|
|---|
| 387 | if (rc == EOK) {
|
|---|
| 388 | printf("Loaded symbol table from %s\n", file_name);
|
|---|
| 389 | free(file_name);
|
|---|
| 390 | return;
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 | free(file_name);
|
|---|
| 394 |
|
|---|
| 395 | rc = asprintf(&file_name, "/srv/%s", app_name);
|
|---|
| 396 | if (rc < 0) {
|
|---|
| 397 | printf("Memory allocation failure.\n");
|
|---|
| 398 | exit(1);
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 401 | rc = symtab_load(file_name, &app_symtab);
|
|---|
| 402 | if (rc == EOK) {
|
|---|
| 403 | printf("Loaded symbol table from %s\n", file_name);
|
|---|
| 404 | free(file_name);
|
|---|
| 405 | return;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | rc = asprintf(&file_name, "/drv/%s/%s", app_name, app_name);
|
|---|
| 409 | if (rc < 0) {
|
|---|
| 410 | printf("Memory allocation failure.\n");
|
|---|
| 411 | exit(1);
|
|---|
| 412 | }
|
|---|
| 413 |
|
|---|
| 414 | rc = symtab_load(file_name, &app_symtab);
|
|---|
| 415 | if (rc == EOK) {
|
|---|
| 416 | printf("Loaded symbol table from %s\n", file_name);
|
|---|
| 417 | free(file_name);
|
|---|
| 418 | return;
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | free(file_name);
|
|---|
| 422 | printf("Failed autoloading symbol table.\n");
|
|---|
| 423 | }
|
|---|
| 424 |
|
|---|
| 425 | static char *get_app_task_name(void)
|
|---|
| 426 | {
|
|---|
| 427 | char dummy_buf;
|
|---|
| 428 | size_t copied, needed, name_size;
|
|---|
| 429 | char *name;
|
|---|
| 430 | int rc;
|
|---|
| 431 |
|
|---|
| 432 | rc = udebug_name_read(phoneid, &dummy_buf, 0, &copied, &needed);
|
|---|
| 433 | if (rc < 0)
|
|---|
| 434 | return NULL;
|
|---|
| 435 |
|
|---|
| 436 | name_size = needed;
|
|---|
| 437 | name = malloc(name_size + 1);
|
|---|
| 438 | rc = udebug_name_read(phoneid, name, name_size, &copied, &needed);
|
|---|
| 439 | if (rc < 0) {
|
|---|
| 440 | free(name);
|
|---|
| 441 | return NULL;
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | assert(copied == name_size);
|
|---|
| 445 | assert(copied == needed);
|
|---|
| 446 | name[copied] = '\0';
|
|---|
| 447 |
|
|---|
| 448 | return name;
|
|---|
| 449 | }
|
|---|
| 450 |
|
|---|
| 451 | /** Format address in symbolic form.
|
|---|
| 452 | *
|
|---|
| 453 | * Formats address as <symbol_name>+<offset> (<address>), if possible,
|
|---|
| 454 | * otherwise as <address>.
|
|---|
| 455 | *
|
|---|
| 456 | * @param addr Address to format.
|
|---|
| 457 | * @return Newly allocated string, address in symbolic form.
|
|---|
| 458 | */
|
|---|
| 459 | static char *fmt_sym_address(uintptr_t addr)
|
|---|
| 460 | {
|
|---|
| 461 | char *name;
|
|---|
| 462 | size_t offs;
|
|---|
| 463 | int rc;
|
|---|
| 464 | char *str;
|
|---|
| 465 |
|
|---|
| 466 | if (app_symtab != NULL) {
|
|---|
| 467 | rc = symtab_addr_to_name(app_symtab, addr, &name, &offs);
|
|---|
| 468 | } else {
|
|---|
| 469 | rc = ENOTSUP;
|
|---|
| 470 | }
|
|---|
| 471 |
|
|---|
| 472 | if (rc == EOK) {
|
|---|
| 473 | rc = asprintf(&str, "%p (%s+%zu)", (void *) addr, name, offs);
|
|---|
| 474 | } else {
|
|---|
| 475 | rc = asprintf(&str, "%p", (void *) addr);
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | if (rc < 0) {
|
|---|
| 479 | printf("Memory allocation error.\n");
|
|---|
| 480 | exit(1);
|
|---|
| 481 | }
|
|---|
| 482 |
|
|---|
| 483 | return str;
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | /** @}
|
|---|
| 487 | */
|
|---|