In CTFs when I'm given some ELF file, it usually wasn't compiled with the -g flag. Is there a way to to somehow edit the file to make it be as if the ELF file was originally compiled with the -g flag? (I guess part of my issue is that I also don't understand exactly what the -g flag adds for gdb, so I'm not sure if its possible to add whatever it adds)
You could try ghidra2dwarf:
Ghidra2Dwarf is a ghidra plugin that allows to exports informations (such as functions, decompiled code, types) from ghidra to dwarf sections inside ELF binaries.
People have been using it to help with CTF challenges since 2020:
Hellf python library can help you modify your elf file to add symbols to the symbol section table.
See an example here