These were VERY hard to program as MS-DOS was intended as a single tasking program.
Many debuggers ran as TSR's.
I think the most popular TSR was Sidekick from Borland. Sidekick included a calculator, notepad, appointment book, basic terminal program, clip board among other things.
TSR's typically hooked the keyboard interrupt looking for a special sequence that would call them up, and interrupt the underlying program. More sophisticated ones would also hook the timer, and allow the 'foreground' program to continue to execute, a form of multitasking.