0

I have a Python program that is feeding JSON input to a binary running in GDB which then reads that input using the C function fread().

The problem is that fread() needs a EOF/Ctrl-D to stop reading but the JSON input I am passing to the binary in GDB are strings so the binary just hangs waiting for more input or a Ctrl-D.

I have red that apparently there isn't a way to pass an EOF instruction using Python. Is there a way to define an instruction in GDB that sends an EOF to the binary instead maybe?

If this was possible I could then trigger that instruction in Python after I send the input.

I am not sure if something like this is possible in GDB using the 'define' feature.

Thanks

Jamiu S.
  • 5,257
  • 5
  • 12
  • 34
Ben S
  • 1
  • 1
  • 1

1 Answers1

0

Once you've sent the generated JSON, close the file descriptor to signal EOF to your C program.

If your generator in written in Python, you should just be able to call f.close() on the file object you wrote the JSON string to. If that is stdout, sys.stdout.close() should do the trick. I would suggest posting the source of your generator program if you want an exact answer.

wkz
  • 2,203
  • 1
  • 15
  • 21
  • Thanks, don't mind posting source but just to clarify, the Python script isn't interacting directly with the C program. The C program is running within GDB to monitor its operations and the Python script is passing instructions and input to GDB which is then passed by GDB to the C program. I am not sure if what you're suggesting would work in this scenario. – Ben S Aug 08 '22 at 07:36