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.2 2005/03/07 05:05:04 dillon Exp $
39 static void dump_debug_stream(struct jstream *js);
40 static int dump_subrecord(struct jstream *js, off_t off, int recsize, int level);
41 static int dump_payload(int16_t rectype, struct jstream *js, off_t off,
42 int recsize, int level);
45 dump_debug(struct jfile *jf)
49 while ((js = jscan_stream(jf)) != NULL) {
50 dump_debug_stream(js);
56 dump_debug_stream(struct jstream *js)
58 struct journal_rawrecbeg head;
61 jsread(js, 0, &head, sizeof(head));
63 sid = head.streamid & JREC_STREAMID_MASK;
64 printf("STREAM %04x {\n", (int)(u_int16_t)head.streamid);
65 if (sid >= JREC_STREAMID_JMIN && sid < JREC_STREAMID_JMAX) {
66 dump_subrecord(js, sizeof(head),
67 head.recsize - sizeof(struct journal_rawrecbeg) -
68 sizeof(struct journal_rawrecend),
71 switch(head.streamid & JREC_STREAMID_MASK) {
72 case JREC_STREAMID_SYNCPT & JREC_STREAMID_MASK:
75 case JREC_STREAMID_PAD & JREC_STREAMID_MASK:
78 case JREC_STREAMID_DISCONT & JREC_STREAMID_MASK:
81 case JREC_STREAMID_ANNOTATE & JREC_STREAMID_MASK:
82 printf(" ANNOTATION\n");
93 dump_subrecord(struct jstream *js, off_t off, int recsize, int level)
95 struct journal_subrecord sub;
102 while (recsize > 0) {
103 if ((error = jsread(js, off, &sub, sizeof(sub))) != 0)
105 printf("%*.*s", level * 4, level * 4, "");
106 printf("@%lld ", off);
107 printf("RECORD %s [%04x/%d]", type_to_name(sub.rectype),
108 (int)(u_int16_t)sub.rectype, sub.recsize);
109 payload = sub.recsize - sizeof(sub);
110 subsize = (sub.recsize + 7) & ~7;
111 if (sub.rectype & JMASK_NESTED) {
114 error = dump_subrecord(js, off + sizeof(sub), payload, level + 1);
115 printf("%*.*s}\n", level * 4, level * 4, "");
116 } else if (sub.rectype & JMASK_SUBRECORD) {
117 printf(" DATA (%d)", payload);
118 error = dump_payload(sub.rectype, js, off + sizeof(sub), payload, level);
123 printf("[unknown content]\n", sub.recsize);
126 subsize = sizeof(sub);
134 dump_payload(int16_t rectype, struct jstream *js, off_t off,
135 int recsize, int level)
137 enum { DT_NONE, DT_STRING, DT_DEC, DT_HEX, DT_OCT,
138 DT_DATA, DT_TIMESTAMP } dt = DT_DATA;
145 error = jsreadp(js, off, (const void **)&buf, recsize);
149 switch(rectype & ~JMASK_LAST) {
184 case JLEAF_RESERVED_0F:
186 case JLEAF_SYMLINKDATA:
229 for (i = 0; i < recsize; ++i)
230 stringout(stdout, buf[i], 1);
236 printf(" %d", (int)*(u_int8_t *)buf);
239 printf(" %d", (int)*(u_int16_t *)buf);
242 printf(" %d", (int)*(u_int32_t *)buf);
245 printf(" %d", (int64_t)*(u_int64_t *)buf);
255 printf(" 0x%02x", (int)*(u_int8_t *)buf);
258 printf(" 0x%04x", (int)*(u_int16_t *)buf);
261 printf(" 0x%08x", (int)*(u_int32_t *)buf);
264 printf(" 0x%016llx", (int64_t)*(u_int64_t *)buf);
274 printf(" %03o", (int)*(u_int8_t *)buf);
277 printf(" %06o", (int)*(u_int16_t *)buf);
280 printf(" %011o", (int)*(u_int32_t *)buf);
283 printf(" %022llo", (int64_t)*(u_int64_t *)buf);
293 time_t t = ((struct timespec *)buf)->tv_sec;
297 strftime(outbuf, sizeof(outbuf), " <%d-%b-%Y %H:%M:%S>", tp);
298 printf("%s", outbuf);
304 for (i = 0; i < recsize; ++i)
305 printf(" %02x", (int)(unsigned char)buf[i]);
307 for (i = 0; i < recsize; ++i)
308 stringout(stdout, buf[i], 0);
312 for (i = 0; i < recsize; i += 16) {
313 printf("%*.*s", level * 4 + 4, level * 4 + 4, "");
314 for (j = i; j < i + 16 && j < recsize; ++j)
315 printf(" %02x", (int)(unsigned char)buf[j]);
316 for (; j < i + 16; ++j)
319 for (j = i; j < i + 16 && j < recsize; ++j)
320 stringout(stdout, buf[j], 0);
323 printf("%*.*s}", level * 4, level * 4, "");