Language-specific information is built into the debugger for some languages, allowing you to express operations like the above in your program's native language, and allowing the debugger to output values in a manner consistent with the syntax of your program's native language. The language you use to build expressions is called the working language.
There are two ways to control the working language — either have the debugger set it automatically, or select it manually yourself. You can use the set language command for either purpose. On startup, the debugger defaults to setting the language automatically. The working language is used to determine how expressions you type are interpreted, how values are printed, etc.
In addition to the working language, every source file that the debugger knows about has its own working language. For some object file formats, the compiler might indicate which language a particular source file is in. However, most of the time the debugger infers the language from the name of the file. The language of a source file controls whether C++ names are demangled — this way backtrace can show each frame appropriately for its own language. There is no way to set the language of a source file from within the debugger.
This is most commonly a problem when you use a program, such as cfront or f2c, that generates C but is written in another language. In that case, make the program use #line directives in its C output; that way the debugger will know the correct language of the source code of the original program, and will display that source code, not the generated C code.
If a source file name ends in one of the following extensions, then the debugger infers that its language is the one indicated.
C source file
C++ source file
Assembler source file. This actually behaves almost like C, but the debugger does not skip over function prologues when stepping.
If you allow the debugger to set the language automatically, expressions are interpreted the same way in your debugging session and your program.
If you wish, you may set the language manually. To do this, issue the command set language lang, where lang is the name of a language, such as c. For a list of the supported languages, type set language.
To have the debugger set the working language automatically, use set language local or set language auto. The debugger then infers the working language. That is, when your program stops in a frame (usually by encountering a breakpoint), the debugger sets the working language to the language recorded for the function in that frame. If the language for a frame is unknown (that is, if the function or block corresponding to the frame was defined in a source file that does not have a recognized extension), the current working language is not changed, and the debugger issues a warning.
This may not seem necessary for most programs, which are written entirely in one source language. However, program modules and libraries written in one source language can be used by a main program written in a different source language. Using the command set language auto in this case frees you from having to set the working language manually.