'How do you print to the REPL from the CPython source?

I am trying to get some printf info from compile.c to the REPL. Specifically, just to get a "hello world" of sorts, I modified compiler_for as follows:

compiler_for(struct compiler *c, stmt_ty s)
{
    basicblock *start, *body, *cleanup, *end;

    printf("entering compiler_for \n");

    start = compiler_new_block(c);
    body = compiler_new_block(c);

I built it using:

 PCbuild/build.bat -E -d -p x64

And ran it on Cygwin as:

   ./go

Here is the detail on the go script and output:

Vostro@DESKTOP-UGP94US /c/Users/Vostro/Downloads/Python-3.10.2/PCbuild/amd64
$ go
hi

Vostro@DESKTOP-UGP94US /c/Users/Vostro/Downloads/Python-3.10.2/PCbuild/amd64
$ cat go
./python.exe target.py

Vostro@DESKTOP-UGP94US /c/Users/Vostro/Downloads/Python-3.10.2/PCbuild/amd64
$ cat target.py
for i in range(1):
    print("hi")

in the amd64 library.

It is not at all surprising that this did not produce an output. I guess I could try to get it to work in the Visual Studio IDE. For whatever reason, I have had no luck building in the IDE (using the .sln), and have not yet tried opening the sln after building with the build.bat to see if the output is in the console output window. Even if it is, however, I'm guessing it would be much handier to see the result in the REPL.

Does anyone know how this is typically done (for example) by the Python contributors when they are debugging or others that make mods to the source?

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source