Skip to content

Commit

Permalink
Annotate varlena headers separately.
Browse files Browse the repository at this point in the history
  • Loading branch information
petergeoghegan committed Apr 9, 2019
1 parent f2d686c commit 3e93485
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -470,6 +470,7 @@ EmitXmlTag()
EmitXmlItemId()
EmitXmlTupleTag()
EmitXmlTupleTagFont()
EmitXmlTupleTagFontTwoName()
```

These routines could be changed to call a per-hexeditor callback. Each
Expand Down
86 changes: 82 additions & 4 deletions pg_hexedit.c
Expand Up @@ -274,6 +274,10 @@ static void EmitXmlTupleTagFont(BlockNumber blkno, OffsetNumber offset,
const char *name, const char *color,
const char *fontColor, uint32 relfileOff,
uint32 relfileOffEnd);
static void EmitXmlTupleTagFontTwoName(BlockNumber blkno, OffsetNumber offset,
const char *name1, const char *name2,
const char *color, const char *fontColor,
uint32 relfileOff, uint32 relfileOffEnd);
static void EmitXmlAttributesHeap(BlockNumber blkno, OffsetNumber offset,
uint32 relfileOff, HeapTupleHeader htup,
int itemSize);
Expand Down Expand Up @@ -1741,6 +1745,43 @@ EmitXmlTupleTagFont(BlockNumber blkno, OffsetNumber offset, const char *name,
printf(" </TAG>\n");
}

/*
* Like EmitXmlTupleTagFont(), but lets caller specify name in two parts
*/
static void
EmitXmlTupleTagFontTwoName(BlockNumber blkno, OffsetNumber offset,
const char *name1, const char *name2,
const char *color, const char *fontColor,
uint32 relfileOff, uint32 relfileOffEnd)
{
char *combinednames;
if (relfileOff > relfileOffEnd)
{
fprintf(stderr, "pg_hexedit error: (%u,%u) tuple tag \"%s - %s\" is malformed (%u > %u)\n",
blkno + segmentBlockDelta, offset, name1, name2, relfileOff,
relfileOffEnd);
exitCode = 1;
return;
}

combinednames = pg_malloc(strlen(name1) + strlen(name2) + 5);
combinednames[0] = '\0';
strcat(combinednames, name1);
strcat(combinednames, " - ");
strcat(combinednames, name2);

printf(" <TAG id=\"%u\">\n", tagNumber++);
printf(" <start_offset>%u</start_offset>\n", relfileOff);
printf(" <end_offset>%u</end_offset>\n", relfileOffEnd);
printf(" <tag_text>(%u,%u) %s</tag_text>\n",
blkno + segmentBlockDelta, offset, combinednames);
printf(" <font_colour>%s</font_colour>\n", fontColor);
printf(" <note_colour>%s</note_colour>\n", color);
printf(" </TAG>\n");

pg_free(combinednames);
}

/*
* Emit wxHexEditor tags for individual non-NULL attributes in heap tuple
*/
Expand Down Expand Up @@ -1891,6 +1932,7 @@ EmitXmlAttributesData(BlockNumber blkno, OffsetNumber offset,
uint32 relfileOff, unsigned char *tupdata, bits8 *t_bits,
int nattrs, int datalen)
{
unsigned char *attptr = tupdata;
int off = 0;
int i;

Expand All @@ -1900,20 +1942,53 @@ EmitXmlAttributesData(BlockNumber blkno, OffsetNumber offset,
char *attname = attnamerel[i];
char *attcolor = attcolorrel[i];
char attalign = attalignrel[i];
int truestartoff = 0;
int truelen;

if (t_bits && att_isnull(i, t_bits))
continue;

if (attlen == -1)
{
off = att_align_pointer(off, attalign, -1, tupdata + off);
char *hdrname = "";

/* Varlena header receives its own minimal tag */
off = att_align_pointer(off, attalign, -1, attptr);
truelen = VARSIZE_ANY(tupdata + off);

if (VARATT_IS_1B(attptr))
{
truestartoff = 1;
truelen -= 1;
if (VARATT_IS_1B_E(attptr))
hdrname = "varattrib_1b_e";
else
hdrname = "varattrib_1b";

EmitXmlTupleTagFontTwoName(blkno, offset, attname, hdrname,
attcolor, COLOR_BROWN,
relfileOff + off,
relfileOff + off);
}
else if (VARATT_IS_4B(attptr))
{
truestartoff = 4;
truelen -= 4;
if (VARATT_IS_4B_U(attptr))
hdrname = "va_4byte";
else if (VARATT_IS_4B_C(attptr))
hdrname = "va_compressed";

EmitXmlTupleTagFontTwoName(blkno, offset, attname, hdrname,
attcolor, COLOR_BROWN,
relfileOff + off,
relfileOff + off + 3);
}
}
else if (attlen == -2)
{
off = att_align_nominal(off, attalign);
truelen = strnlen((char *) tupdata + off, datalen - off) + 1;
truelen = strnlen((char *) attptr, datalen - off) + 1;
}
else
{
Expand All @@ -1929,10 +2004,13 @@ EmitXmlAttributesData(BlockNumber blkno, OffsetNumber offset,
return;
}

EmitXmlTupleTag(blkno, offset, attname, attcolor, relfileOff + off,
relfileOff + off + truelen - 1);
EmitXmlTupleTag(blkno, offset, attname, attcolor,
relfileOff + off + truestartoff,
relfileOff + off + truestartoff + truelen - 1);

/* Get possible address of next attribute, handling alignment */
off = att_addlength_pointer(off, attlen, tupdata + off);
attptr = tupdata + off;
}
}

Expand Down

0 comments on commit 3e93485

Please sign in to comment.