1997-08-05 00:19:57 +08:00
|
|
|
|
/*-------------------------------------------------------------------------
|
1998-01-17 06:23:43 +08:00
|
|
|
|
* Copyright (C) 1997 National Center for Supercomputing Applications.
|
1997-08-05 00:19:57 +08:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*
|
1998-01-17 06:23:43 +08:00
|
|
|
|
* Created: debug.c
|
|
|
|
|
* Jul 18 1997
|
|
|
|
|
* Robb Matzke <matzke@llnl.gov>
|
1997-08-05 00:19:57 +08:00
|
|
|
|
*
|
1998-01-17 06:23:43 +08:00
|
|
|
|
* Purpose: Debugs an existing HDF5 file at a low level.
|
1997-08-05 00:19:57 +08:00
|
|
|
|
*
|
1998-01-17 06:23:43 +08:00
|
|
|
|
* Modifications:
|
1997-08-05 00:19:57 +08:00
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
1997-08-16 00:51:34 +08:00
|
|
|
|
#include <H5private.h>
|
1998-03-18 06:46:27 +08:00
|
|
|
|
#include <H5Iprivate.h>
|
1997-08-16 00:51:34 +08:00
|
|
|
|
#include <H5Bprivate.h>
|
1998-02-26 03:13:49 +08:00
|
|
|
|
#include <H5Pprivate.h>
|
1997-08-16 00:51:34 +08:00
|
|
|
|
#include <H5Fprivate.h>
|
|
|
|
|
#include <H5Gprivate.h>
|
1998-03-31 03:24:08 +08:00
|
|
|
|
#include <H5HGprivate.h>
|
|
|
|
|
#include <H5HLprivate.h>
|
1997-08-16 00:51:34 +08:00
|
|
|
|
#include <H5Oprivate.h>
|
2000-05-10 02:14:33 +08:00
|
|
|
|
|
1999-08-11 04:21:32 +08:00
|
|
|
|
/* File drivers */
|
|
|
|
|
#include <H5FDfamily.h>
|
2000-05-10 02:14:33 +08:00
|
|
|
|
|
1998-01-17 06:23:43 +08:00
|
|
|
|
#define INDENT 3
|
|
|
|
|
#define VCOL 50
|
1998-04-18 05:29:43 +08:00
|
|
|
|
|
1997-08-05 00:19:57 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
1998-01-17 06:23:43 +08:00
|
|
|
|
* Function: main
|
1997-08-05 00:19:57 +08:00
|
|
|
|
*
|
1998-01-17 06:23:43 +08:00
|
|
|
|
* Usage: debug FILENAME [OFFSET]
|
1997-08-05 00:19:57 +08:00
|
|
|
|
*
|
1998-01-17 06:23:43 +08:00
|
|
|
|
* Return: Success: exit (0)
|
1997-08-05 00:19:57 +08:00
|
|
|
|
*
|
1998-01-17 06:23:43 +08:00
|
|
|
|
* Failure: exit (non-zero)
|
1997-08-05 00:19:57 +08:00
|
|
|
|
*
|
1998-01-17 06:23:43 +08:00
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* matzke@llnl.gov
|
|
|
|
|
* Jul 18 1997
|
1997-08-05 00:19:57 +08:00
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
int
|
1998-01-17 06:23:43 +08:00
|
|
|
|
main(int argc, char *argv[])
|
1997-08-05 00:19:57 +08:00
|
|
|
|
{
|
1998-11-19 02:40:09 +08:00
|
|
|
|
hid_t fid, plist=H5P_DEFAULT;
|
|
|
|
|
H5F_t *f;
|
1999-07-29 03:37:35 +08:00
|
|
|
|
haddr_t addr=0, extra=0;
|
1998-11-19 02:40:09 +08:00
|
|
|
|
uint8_t sig[16];
|
|
|
|
|
intn i, ndims;
|
|
|
|
|
herr_t status = SUCCEED;
|
1997-08-05 00:19:57 +08:00
|
|
|
|
|
2000-09-15 01:26:37 +08:00
|
|
|
|
if (argc == 1) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Usage: %s filename [signature addr [extra]]\n", argv[0]);
|
|
|
|
|
HDexit(1);
|
|
|
|
|
}
|
|
|
|
|
|
1998-01-17 06:23:43 +08:00
|
|
|
|
/*
|
|
|
|
|
* Open the file and get the file descriptor.
|
|
|
|
|
*/
|
1998-04-09 05:43:02 +08:00
|
|
|
|
if (strchr (argv[1], '%')) {
|
|
|
|
|
plist = H5Pcreate (H5P_FILE_ACCESS);
|
1999-08-11 04:21:32 +08:00
|
|
|
|
H5Pset_fapl_family (plist, 0, H5P_DEFAULT);
|
1998-04-09 05:43:02 +08:00
|
|
|
|
}
|
|
|
|
|
if ((fid = H5Fopen(argv[1], H5F_ACC_RDONLY, plist)) < 0) {
|
1998-01-17 06:23:43 +08:00
|
|
|
|
fprintf(stderr, "cannot open file\n");
|
|
|
|
|
HDexit(1);
|
|
|
|
|
}
|
1998-03-18 06:46:27 +08:00
|
|
|
|
if (NULL == (f = H5I_object(fid))) {
|
1998-01-17 06:23:43 +08:00
|
|
|
|
fprintf(stderr, "cannot obtain H5F_t pointer\n");
|
|
|
|
|
HDexit(2);
|
|
|
|
|
}
|
1998-04-09 05:43:02 +08:00
|
|
|
|
|
1998-01-17 06:23:43 +08:00
|
|
|
|
/*
|
|
|
|
|
* Parse command arguments.
|
|
|
|
|
*/
|
|
|
|
|
if (argc > 2) {
|
|
|
|
|
printf("New address: %s\n", argv[2]);
|
1999-07-29 02:25:43 +08:00
|
|
|
|
addr = HDstrtoll(argv[2], NULL, 0);
|
1998-01-17 06:23:43 +08:00
|
|
|
|
}
|
|
|
|
|
if (argc > 3) {
|
1999-07-29 02:25:43 +08:00
|
|
|
|
extra = HDstrtoll(argv[3], NULL, 0);
|
1998-01-17 06:23:43 +08:00
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* Read the signature at the specified file position.
|
|
|
|
|
*/
|
1999-07-29 02:25:43 +08:00
|
|
|
|
HDfprintf(stdout, "Reading signature at address %a (rel)\n", addr);
|
1999-08-11 04:21:32 +08:00
|
|
|
|
if (H5F_block_read(f, addr, (hsize_t)sizeof(sig), H5P_DEFAULT, sig)<0) {
|
1998-01-17 06:23:43 +08:00
|
|
|
|
fprintf(stderr, "cannot read signature\n");
|
|
|
|
|
HDexit(3);
|
|
|
|
|
}
|
|
|
|
|
if (!HDmemcmp(sig, H5F_SIGNATURE, H5F_SIGNATURE_LEN)) {
|
|
|
|
|
/*
|
|
|
|
|
* Debug the boot block.
|
|
|
|
|
*/
|
1999-07-29 02:25:43 +08:00
|
|
|
|
status = H5F_debug(f, addr, stdout, 0, VCOL);
|
1997-08-05 00:19:57 +08:00
|
|
|
|
|
1998-03-31 03:24:08 +08:00
|
|
|
|
} else if (!HDmemcmp(sig, H5HL_MAGIC, H5HL_SIZEOF_MAGIC)) {
|
1998-01-17 06:23:43 +08:00
|
|
|
|
/*
|
1998-03-31 03:24:08 +08:00
|
|
|
|
* Debug a local heap.
|
1998-01-17 06:23:43 +08:00
|
|
|
|
*/
|
1999-07-29 02:25:43 +08:00
|
|
|
|
status = H5HL_debug(f, addr, stdout, 0, VCOL);
|
1998-03-31 03:24:08 +08:00
|
|
|
|
|
|
|
|
|
} else if (!HDmemcmp (sig, H5HG_MAGIC, H5HG_SIZEOF_MAGIC)) {
|
|
|
|
|
/*
|
|
|
|
|
* Debug a global heap collection.
|
|
|
|
|
*/
|
1999-07-29 02:25:43 +08:00
|
|
|
|
status = H5HG_debug (f, addr, stdout, 0, VCOL);
|
1997-08-05 00:19:57 +08:00
|
|
|
|
|
1998-01-17 06:23:43 +08:00
|
|
|
|
} else if (!HDmemcmp(sig, H5G_NODE_MAGIC, H5G_NODE_SIZEOF_MAGIC)) {
|
|
|
|
|
/*
|
|
|
|
|
* Debug a symbol table node.
|
|
|
|
|
*/
|
1999-07-29 02:25:43 +08:00
|
|
|
|
status = H5G_node_debug(f, addr, stdout, 0, VCOL, extra);
|
1997-08-05 00:19:57 +08:00
|
|
|
|
|
1998-01-17 06:23:43 +08:00
|
|
|
|
} else if (!HDmemcmp(sig, H5B_MAGIC, H5B_SIZEOF_MAGIC)) {
|
|
|
|
|
/*
|
|
|
|
|
* Debug a B-tree. B-trees are debugged through the B-tree
|
|
|
|
|
* subclass. The subclass identifier is the byte immediately
|
|
|
|
|
* after the B-tree signature.
|
|
|
|
|
*/
|
1998-04-18 05:29:43 +08:00
|
|
|
|
H5B_subid_t subtype = (H5B_subid_t)sig[H5B_SIZEOF_MAGIC];
|
|
|
|
|
|
1998-01-17 06:23:43 +08:00
|
|
|
|
switch (subtype) {
|
|
|
|
|
case H5B_SNODE_ID:
|
1999-07-29 02:25:43 +08:00
|
|
|
|
status = H5G_node_debug(f, addr, stdout, 0, VCOL, extra);
|
1998-01-17 06:23:43 +08:00
|
|
|
|
break;
|
1997-08-05 00:19:57 +08:00
|
|
|
|
|
1998-04-18 05:29:43 +08:00
|
|
|
|
case H5B_ISTORE_ID:
|
1999-07-29 02:25:43 +08:00
|
|
|
|
ndims = (int)extra;
|
|
|
|
|
status = H5F_istore_debug (f, addr, stdout, 0, VCOL, ndims);
|
1998-04-18 05:29:43 +08:00
|
|
|
|
break;
|
|
|
|
|
|
1998-01-17 06:23:43 +08:00
|
|
|
|
default:
|
1998-11-19 02:40:09 +08:00
|
|
|
|
fprintf(stderr, "Unknown B-tree subtype %u\n",
|
|
|
|
|
(unsigned)(subtype));
|
1998-01-17 06:23:43 +08:00
|
|
|
|
HDexit(4);
|
|
|
|
|
}
|
1997-08-05 00:19:57 +08:00
|
|
|
|
|
1998-02-10 03:37:40 +08:00
|
|
|
|
} else if (sig[0] == H5O_VERSION) {
|
1998-01-17 06:23:43 +08:00
|
|
|
|
/*
|
|
|
|
|
* This could be an object header. Since they don't have a signature
|
|
|
|
|
* it's a somewhat "ify" detection.
|
|
|
|
|
*/
|
1999-07-29 02:25:43 +08:00
|
|
|
|
status = H5O_debug(f, addr, stdout, 0, VCOL);
|
1997-08-08 03:23:00 +08:00
|
|
|
|
|
1998-01-17 06:23:43 +08:00
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* Got some other unrecognized signature.
|
|
|
|
|
*/
|
|
|
|
|
printf("%-*s ", VCOL, "Signature:");
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
|
if (sig[i] > ' ' && sig[i] <= '~' && '\\' != sig[i]) {
|
|
|
|
|
HDputchar(sig[i]);
|
|
|
|
|
} else if ('\\' == sig[i]) {
|
|
|
|
|
HDputchar('\\');
|
|
|
|
|
HDputchar('\\');
|
|
|
|
|
} else {
|
|
|
|
|
printf("\\%03o", sig[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HDputchar('\n');
|
1997-08-05 00:19:57 +08:00
|
|
|
|
|
1998-01-17 06:23:43 +08:00
|
|
|
|
fprintf(stderr, "unknown signature\n");
|
|
|
|
|
HDexit(4);
|
|
|
|
|
}
|
1997-08-08 03:23:00 +08:00
|
|
|
|
|
1998-01-17 06:23:43 +08:00
|
|
|
|
if (status < 0) {
|
|
|
|
|
fprintf(stderr, "An error occurred\n");
|
|
|
|
|
HDexit(5);
|
|
|
|
|
}
|
|
|
|
|
H5Fclose(fid);
|
1998-02-10 03:37:40 +08:00
|
|
|
|
return 0;
|
1997-08-05 00:19:57 +08:00
|
|
|
|
}
|