Debugging image resources

I work a lot with image processing. There is a lot of transformations and sub images extraction. Often, it would be great to actually see those images when debugging. Quick Google search pointed me to the dump command present in gdb.

In short, to get the memory dump, you would do something like this:

set $source=pointer_to_the_memory
set $size_of_the_dump=4096
dump memory filename.bin $source $source+size_of_the_dump

You have to know the size of your data. For an image it means: width, height, color depth.

Next step was to actually visualize this data as an image. I’ve put together a small Python script. The goal was to make it as simple as possible - I was in a rush. This solution is pretty cumbersome compared to what a workflow like that could be…

import pathlib
from PIL import Image
import sys

full_path = pathlib.Path(sys.argv[1])
width = int(sys.argv[2])
height = int(sys.argv[3])

print(f'Reading binary image file: {full_path}')

img = Image.frombytes('L', (width, height), full_path.read_bytes())
img.show()

That worked well, but it also made me think. Why isn’t it a standard? I know that viewing images is a pretty specific request, but the idea can be extrapolated. Why don’t we have proper tools to investigate the data during debugging?

Maybe we do and I just don’t know about it…? I guess it’s something I need to research.