2 * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sbin/jscan/dump_debug.c,v 1.7 2005/09/07 19:10:09 dillon Exp $
39 static void dump_debug_stream(struct jstream *js);
40 static int dump_debug_subrecord(struct jstream *js, off_t *off,
41 off_t recsize, int level);
42 static int dump_debug_payload(int16_t rectype, struct jstream *js, off_t off,
43 int recsize, int level);
46 dump_debug(struct jsession *ss, struct jdata *jd)
50 if ((js = jaddrecord(ss, jd)) != NULL) {
51 dump_debug_stream(js);
54 jsession_update_transid(ss, jd->jd_transid);
58 dump_debug_stream(struct jstream *js)
60 struct journal_rawrecbeg head;
63 jsread(js, 0, &head, sizeof(head));
65 sid = head.streamid & JREC_STREAMID_MASK;
66 printf("STREAM %04x %016jx {\n",
67 (int)(u_int16_t)head.streamid,
68 (uintmax_t)head.transid);
69 if (sid >= JREC_STREAMID_JMIN && sid < JREC_STREAMID_JMAX) {
70 off_t off = sizeof(head);
72 dump_debug_subrecord(js, &off,
73 js->js_normalized_total - sizeof(head),
76 switch(head.streamid & JREC_STREAMID_MASK) {
77 case JREC_STREAMID_SYNCPT & JREC_STREAMID_MASK:
80 case JREC_STREAMID_PAD & JREC_STREAMID_MASK:
83 case JREC_STREAMID_DISCONT & JREC_STREAMID_MASK:
86 case JREC_STREAMID_ANNOTATE & JREC_STREAMID_MASK:
87 printf(" ANNOTATION\n");
98 dump_debug_subrecord(struct jstream *js, off_t *off, off_t recsize, int level)
100 struct journal_subrecord sub;
107 while (recsize > 0) {
108 if ((error = jsread(js, base, &sub, sizeof(sub))) != 0) {
111 printf("%*.*s", level * 4, level * 4, "");
112 printf("@%jd ", (intmax_t)base);
113 printf("RECORD %s [%04x/%d]", type_to_name(sub.rectype),
114 (int)(u_int16_t)sub.rectype, sub.recsize);
115 if (sub.recsize == -1) {
116 if ((sub.rectype & JMASK_NESTED) == 0) {
117 printf("Record size of -1 only works for nested records\n");
121 payload = 0x7FFFFFFF;
122 subsize = 0x7FFFFFFF;
124 payload = sub.recsize - sizeof(sub);
125 subsize = (sub.recsize + 7) & ~7;
127 if (sub.rectype & JMASK_NESTED) {
130 *off = base + sizeof(sub);
131 error = dump_debug_subrecord(js, off, payload, level + 1);
133 printf("%*.*s}\n", level * 4, level * 4, "");
134 } else if (sub.rectype & JMASK_SUBRECORD) {
135 printf(" DATA (%d)", payload);
136 error = dump_debug_payload(sub.rectype, js, base + sizeof(sub), payload, level);
137 *off = base + sizeof(sub) + payload;
140 printf("[%d bytes of unknown content]\n", sub.recsize);
144 if (sub.recsize == -1) {
145 recsize -= ((*off + 7) & ~7) - base;
146 base = (*off + 7) & ~7;
149 subsize = sizeof(sub);
153 if (sub.rectype & JMASK_LAST)
161 dump_debug_payload(int16_t rectype, struct jstream *js, off_t off,
162 int recsize, int level)
164 enum { DT_NONE, DT_STRING, DT_DEC, DT_HEX, DT_OCT,
165 DT_DATA, DT_TIMESTAMP } dt = DT_DATA;
171 error = jsreadp(js, off, (const void **)&buf, recsize);
175 switch(rectype & ~JMASK_LAST) {
211 case JLEAF_RESERVED_0F:
213 case JLEAF_SYMLINKDATA:
256 for (i = 0; i < recsize; ++i)
257 stringout(stdout, buf[i], 1);
263 printf(" %d", (int)*(const u_int8_t *)buf);
266 printf(" %d", (int)*(const u_int16_t *)buf);
269 printf(" %d", (int)*(const u_int32_t *)buf);
272 printf(" %jd", (intmax_t)*(const int64_t *)buf);
282 printf(" 0x%02x", (int)*(const u_int8_t *)buf);
285 printf(" 0x%04x", (int)*(const u_int16_t *)buf);
288 printf(" 0x%08x", (int)*(const u_int32_t *)buf);
291 printf(" 0x%016jx", (uintmax_t)*(const u_int64_t *)buf);
301 printf(" %03o", (int)*(const u_int8_t *)buf);
304 printf(" %06o", (int)*(const u_int16_t *)buf);
307 printf(" %011o", (int)*(const u_int32_t *)buf);
310 printf(" %022jo", (intmax_t)*(const int64_t *)buf);
320 time_t t = ((const struct timespec *)buf)->tv_sec;
324 strftime(outbuf, sizeof(outbuf), " <%d-%b-%Y %H:%M:%S>", tp);
325 printf("%s", outbuf);
331 for (i = 0; i < recsize; ++i)
332 printf(" %02x", (int)(unsigned char)buf[i]);
334 for (i = 0; i < recsize; ++i)
335 stringout(stdout, buf[i], 0);
339 for (i = 0; i < recsize; i += 16) {
340 printf("%*.*s", level * 4 + 4, level * 4 + 4, "");
341 for (j = i; j < i + 16 && j < recsize; ++j)
342 printf(" %02x", (int)(unsigned char)buf[j]);
343 for (; j < i + 16; ++j)
346 for (j = i; j < i + 16 && j < recsize; ++j)
347 stringout(stdout, buf[j], 0);
350 printf("%*.*s}", level * 4, level * 4, "");