Tue Aug 30 22:37:36 2022 UTC ()
ddb(4): Use db_num_to_strbuf in db_symstr.

Simplifies it and will make safer to use.


(riastradh)
diff -r1.69 -r1.70 src/sys/ddb/db_sym.c

cvs diff -r1.69 -r1.70 src/sys/ddb/db_sym.c (expand / switch to unified diff)

--- src/sys/ddb/db_sym.c 2021/12/13 03:17:50 1.69
+++ src/sys/ddb/db_sym.c 2022/08/30 22:37:36 1.70
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: db_sym.c,v 1.69 2021/12/13 03:17:50 kre Exp $ */ 1/* $NetBSD: db_sym.c,v 1.70 2022/08/30 22:37:36 riastradh Exp $ */
2 2
3/* 3/*
4 * Mach Operating System 4 * Mach Operating System
5 * Copyright (c) 1991,1990 Carnegie Mellon University 5 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Permission to use, copy, modify and distribute this software and its 8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright 9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the 10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions 11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation. 12 * thereof, and that both notices appear in supporting documentation.
13 * 13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * 17 *
18 * Carnegie Mellon requests users of this software to return to 18 * Carnegie Mellon requests users of this software to return to
19 * 19 *
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science 21 * School of Computer Science
22 * Carnegie Mellon University 22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890 23 * Pittsburgh PA 15213-3890
24 * 24 *
25 * any improvements or extensions that they make and grant Carnegie the 25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes. 26 * rights to redistribute these changes.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: db_sym.c,v 1.69 2021/12/13 03:17:50 kre Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: db_sym.c,v 1.70 2022/08/30 22:37:36 riastradh Exp $");
31 31
32#ifdef _KERNEL_OPT 32#ifdef _KERNEL_OPT
33#include "opt_ddbparam.h" 33#include "opt_ddbparam.h"
34#endif 34#endif
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/proc.h> 37#include <sys/proc.h>
38#include <sys/systm.h> 38#include <sys/systm.h>
39#include <sys/ksyms.h> 39#include <sys/ksyms.h>
40 40
41#include <ddb/ddb.h> 41#include <ddb/ddb.h>
42 42
43static void db_symsplit(char *, char **, char **); 43static void db_symsplit(char *, char **, char **);
@@ -362,27 +362,27 @@ db_symstr(char *buf, size_t buflen, db_e @@ -362,27 +362,27 @@ db_symstr(char *buf, size_t buflen, db_e
362 } 362 }
363#ifdef notyet 363#ifdef notyet
364 if (strategy & KSYMS_PROC) { 364 if (strategy & KSYMS_PROC) {
365 if (ksyms_fmaddr(off, &filename, &linenum) == 0) 365 if (ksyms_fmaddr(off, &filename, &linenum) == 0)
366 snprintf(buf + strlen(buf), 366 snprintf(buf + strlen(buf),
367 buflen - strlen(buf), 367 buflen - strlen(buf),
368 " [%s:%d]", filename, linenum); 368 " [%s:%d]", filename, linenum);
369 } 369 }
370#endif 370#endif
371 return; 371 return;
372 } 372 }
373 } 373 }
374out: 374out:
375 strlcpy(buf, db_num_to_str(off), buflen); 375 db_num_to_strbuf(off, buf, buflen);
376#endif 376#endif
377} 377}
378 378
379void 379void
380db_printsym(db_expr_t off, db_strategy_t strategy, 380db_printsym(db_expr_t off, db_strategy_t strategy,
381 void (*pr)(const char *, ...)) 381 void (*pr)(const char *, ...))
382{ 382{
383 const char *name; 383 const char *name;
384#ifdef _KERNEL 384#ifdef _KERNEL
385 const char *mod; 385 const char *mod;
386 unsigned long uval; 386 unsigned long uval;
387 long val; 387 long val;
388#endif 388#endif