4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
32 #include <sys/param.h>
44 hexstr_to_num(const char *str
)
47 size_t i
, len
= strlen(str
);
49 for (i
= 0; i
< len
; i
++)
50 if (str
[i
] >= '0' && str
[i
] <= '9')
51 num
= num
* 16 +((int)str
[i
] - (int)'0');
52 else if (str
[i
] >= 'a' && str
[i
] <= 'f')
53 num
= num
* 16 +((int)str
[i
] - (int)'a' + 10);
54 else if (str
[i
] >= 'A' && str
[i
] <= 'F')
55 num
= num
* 16 + ((int)str
[i
] - (int)'A' + 10);
62 proc_string_read(struct ps_prochandle
*ph
, ulong_t addr
, char *buf
, int bufsiz
)
64 char intbuf
[STBUFSIZ
];
65 int bufind
= 0, intbufind
= STBUFSIZ
, cont
= 1;
68 if (lseek(ph
->pp_asfd
, addr
, SEEK_SET
) == -1)
70 while (cont
&& (bufind
< bufsiz
)) {
71 if (intbufind
>= bufbytes
) {
72 if ((bufbytes
= read(ph
->pp_asfd
, intbuf
,
77 buf
[bufind
] = intbuf
[intbufind
];
78 if (buf
[bufind
] == '\0')
87 print_varstring(struct ps_prochandle
*ph
, const char *varname
)
89 (void) printf("print_varstring: %s\n", varname
);
90 if (strcmp(varname
, "regs") == 0) {
91 (void) display_all_regs(ph
);
94 print_mach_varstring(ph
, varname
);
98 print_mem(struct ps_prochandle
*ph
, ulong_t address
, int count
, char *format
)
100 (void) printf("\n%17s:", print_address_ps(ph
, address
, FLG_PAP_SONAME
));
102 if ((*format
== 'X') || (*format
== 'x')) {
105 for (i
= 0; i
< count
; i
++) {
108 (void) printf("\n 0x%08lx: ", address
);
110 if (ps_pread(ph
, address
, (char *)&word
,
111 sizeof (unsigned long)) != PS_OK
) {
112 (void) printf("\nfailed to read memory at: "
116 (void) printf(" 0x%08lx", word
);
119 (void) putchar('\n');
123 if (*format
== 'b') {
126 for (i
= 0; i
< count
; i
++, address
++) {
130 (void) printf("\n 0x%08lx: ", address
);
132 if (ps_pread(ph
, address
, (char *)&byte
,
133 sizeof (unsigned char)) != PS_OK
) {
134 (void) fprintf(stderr
, "\nfailed to read byte "
135 "at: 0x%lx\n", address
);
138 (void) printf(" %02x", (unsigned)byte
);
140 (void) putchar('\n');
144 if (*format
== 's') {
145 char buf
[MAXPATHLEN
];
146 if (proc_string_read(ph
, address
, buf
,
147 MAXPATHLEN
) != RET_OK
) {
148 (void) printf("unable to read string at: %lx\n",
152 (void) printf(" %s\n", buf
);