-
Notifications
You must be signed in to change notification settings - Fork 138
NULL_FILE
Default Initialization
The primary place where NULL_FILE_ID (-2) is set is during the default initialization of Sg_File_Info objects. support.C:2202
In the ROSETTA code generation system, the file_id field is initialized with NULL_FILE_ID as its default value. support.C:2221-2222
Similarly, the physical_file_id field also defaults to NULL_FILE_ID.
breakpoints do not catch a place it is set
$ gdb -args rose-compiler -c main.c
...
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from rose-compiler...done.
(gdb) r
Starting program: /home/liao6/workspace/rose/installed/bin/rose-compiler -c main.c
...
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[Detaching after fork from child process 1817716]
[Inferior 1 (process 1817412) exited normally]
(gdb) b main
Breakpoint 1 at 0x413224: file ../../src/rose-compiler.C, line 9.
(gdb) r
Starting program: /home/liao6/workspace/rose/installed/bin/rose-compiler -c main.c
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Breakpoint 1, main (argc=3, argv=0x7fffffffa5e8) at ../../src/rose-compiler.C:9
9 ROSE_INITIALIZE;
(gdb) n
10 std::vector<std::string> args(argv, argv+argc);
(gdb)
37 SgProject * project = args.size() > 1 ? frontend(args) : new SgProject(); // TODO this behavior should be part of ::frontend(std::vector<std::string> const &)
(gdb)
39 auto status = backend(project);
(gdb) p SageInterface::printAST2TextFile(project,"main.c.AST.txt",false)
$1 = void
# switch to bash shell, view the generatedAST.txt file, find the non-defining declaration associated with main()
(gdb) p ((SgFunctionDeclaration*)(0x7fffe8b2b2c8))->class_name()
$2 = {static npos = 18446744073709551615, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x1152b30 "SgFunctionDeclaration"}, _M_string_length = 21, {
_M_local_buf = "\025\000\000\000\000\000\000\000?\244\377\377\377\177\000", _M_allocated_capacity = 21}}
(gdb) p ((SgFunctionDeclaration*)(0x7fffe8b2b2c8))->get_file_info()
$3 = (Sg_File_Info *) 0x7fffe9b3fc90
(gdb) p ((SgFunctionDeclaration*)(0x7fffe8b2b2c8))->get_file_info()->display()
Inside of Sg_File_Info::display() of this pointer = 0x7fffe9b3fc90
isTransformation = false
isCompilerGenerated = false
isOutputInCodeGeneration = true (output in code generator)
isShared = false
isFrontendSpecific = false
isSourcePositionUnavailableInFrontend = true (source position unavailable in frontend)
isCommentOrDirective = false
isToken = false
isDefaultArgument = false
isImplicitCast = false
(computed) filename = NULL_FILE
(computed) line = 0 column = 0
(computed) physical_file_id = -2 = NULL_FILE
(internal) physical_file_id = -2 = NULL_FILE
(internal) physical_file_id = -2 = NULL_FILE
(computed) physical_line = 0
source_sequence_number = 0
$4 = void
# now try to catch when the file info object is set to NULL_FILE
(gdb) b Sg_File_Info::set_file_id(int)
Breakpoint 2 at 0x7ffff3550e05: file Cxx_Grammar.C, line 16410.
(gdb) cond 2 (unsigned long)this==(unsigned long)0x7fffe9b3fc90
(gdb) r
(gdb) b Sg_File_Info::post_construction_initialization()
Breakpoint 5 at 0x7ffff3550822: file Cxx_Grammar.C, line 16311.
(gdb) cond 5 (unsigned long)this==(unsigned long)0x7fffe9b3fc90
(gdb) r
Starting program: /home/liao6/workspace/rose/installed/bin/rose-compiler -c main.c
warning: File "/nfs/casc/overture/ROSE/opt/rhel8/x86_64/gcc/10.3.0/mpc/1.0.3/mpfr/3.1.4/gmp/6.1.0/lib64/libstdc++.so.6.0.28-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Breakpoint 1, main (argc=3, argv=0x7fffffffa5e8) at ../../src/rose-compiler.C:9
9 ROSE_INITIALIZE;
(gdb) c
Continuing.
Breakpoint 5, Sg_File_Info::post_construction_initialization (this=0x7fffe9b3fc90) at Cxx_Grammar.C:16311
16311 preventConstructionOnStack(this);
(gdb) bt
#0 Sg_File_Info::post_construction_initialization (this=0x7fffe9b3fc90) at Cxx_Grammar.C:16311
#1 0x00007ffff3550580 in Sg_File_Info::Sg_File_Info (this=0x7fffe9b3fc90, filename=..., line=0, col=0) at Cxx_Grammar.C:16272
#2 0x00007ffff354eb76 in Sg_File_Info::generateDefaultFileInfo () at Cxx_Grammar.C:15837
#3 0x00007ffff4dd8f73 in SageInterface::setSourcePositionToDefault<SgLocatedNode> (node=0x7fffea0b5030) at ../../../../../src/frontend/SageIII/sageInterface/sageInterface.C:7161
#4 0x00007ffff4d7636e in SageInterface::setSourcePosition (node=0x7fffea0b5030) at ../../../../../src/frontend/SageIII/sageInterface/sageInterface.C:7562
#5 0x00007ffff4d75efe in SageInterface::setOneSourcePositionNull (node=0x7fffea0b5030) at ../../../../../src/frontend/SageIII/sageInterface/sageInterface.C:7338
#6 0x00007ffff4cc663c in SageBuilder::buildInitializedName_nfi (name=..., type=0x7fffe96d3010, init=0x0, declptr=0x0) at ../../../../../src/frontend/SageIII/sageInterface/sageBuilder.C:1275
... edgRose related call stack info ommitted here....
#17 0x00007ffff34695cb in SgSourceFile::build_C_and_Cxx_AST (this=0x7fffea439010, argv=..., inputCommandLine=...) at ../../../../src/frontend/SageIII/sage_support/sage_support.C:4085
#18 0x00007ffff346a262 in SgSourceFile::buildAST (this=0x7fffea439010, argv=..., inputCommandLine=...) at ../../../../src/frontend/SageIII/sage_support/sage_support.C:4366
#19 0x00007ffff3466db2 in SgFile::callFrontEnd (this=0x7fffea439010) at ../../../../src/frontend/SageIII/sage_support/sage_support.C:2121
#20 0x00007ffff3463ad2 in SgSourceFile::callFrontEnd (this=0x7fffea439010) at ../../../../src/frontend/SageIII/sage_support/sage_support.C:1588
#21 0x00007ffff346232c in SgFile::runFrontend (this=0x7fffea439010, nextErrorCode=@0x7fffffff969c: 0) at ../../../../src/frontend/SageIII/sage_support/sage_support.C:1221
#22 0x00007ffff3468226 in Rose::Frontend::RunSerial (project=0x7fffea5a5010) at ../../../../src/frontend/SageIII/sage_support/sage_support.C:3410
#23 0x00007ffff3467f13 in Rose::Frontend::Run (project=0x7fffea5a5010) at ../../../../src/frontend/SageIII/sage_support/sage_support.C:3335
#24 0x00007ffff3463ec9 in SgProject::RunFrontend (this=0x7fffea5a5010) at ../../../../src/frontend/SageIII/sage_support/sage_support.C:1613
#25 0x00007ffff3464417 in SgProject::parse (this=0x7fffea5a5010) at ../../../../src/frontend/SageIII/sage_support/sage_support.C:1670
#26 0x00007ffff34633b9 in SgProject::parse (this=0x7fffea5a5010, argv=...) at ../../../../src/frontend/SageIII/sage_support/sage_support.C:1524
#27 0x00007ffff5f6683d in frontend (argv=..., frontendConstantFolding=false) at ../../../src/roseSupport/utility_functions.C:769
#28 0x0000000000413298 in main (argc=3, argv=0x7fffffffa5e8) at ../../src/rose-compiler.C:37
what does (computed) mean in the following context?
(gdb) p ((Sg_File_Info*)(0x7fffe9b3fc90))->display()
Inside of Sg_File_Info::display() of this pointer = 0x7fffe9b3fc90
isTransformation = false
isCompilerGenerated = false
isOutputInCodeGeneration = true (output in code generator)
isShared = false
isFrontendSpecific = false
isSourcePositionUnavailableInFrontend = true (source position unavailable in frontend)
isCommentOrDirective = false
isToken = false
isDefaultArgument = false
isImplicitCast = false
(computed) filename = NULL_FILE
(computed) line = 0 column = 0
(computed) physical_file_id = -2 = NULL_FILE
(internal) physical_file_id = -2 = NULL_FILE
(internal) physical_file_id = -2 = NULL_FILE
(computed) physical_line = 0
source_sequence_number = 0
$6 = void
In the context of the Sg_File_Info::display() output you're showing, "(computed)" indicates that these values are calculated dynamically rather than stored directly as data members in the Sg_File_Info object.
Looking at the ROSE codebase, Sg_File_Info is the core class that stores source position information for AST nodes. rose-full:5340-5354 The "(computed)" prefix appears in debug output to distinguish between values that are:
-
Stored directly as data members (like the classification flags)
-
Computed on-demand through getter functions that may perform calculations or lookups
For example, the (computed) filename = NULL_FILE indicates that when you call get_filenameString() or similar methods, the filename is computed from internal file ID mappings rather than being stored as a string directly. rose-full:5551-5552
The (computed) physical_file_id = -2 = NULL_FILE shows that the physical file ID is being computed, and in this case resolves to the special value -2 which corresponds to NULL_FILE_ID. rose-full:5584-5594
This design allows ROSE to maintain efficient storage while providing computed access to derived information like filenames (which are looked up from ID-to-name mappings) and physical file positions (which may need to account for preprocessor transformations). rose-full:5568-5577
The "(internal)" labels you see in the same output likely refer to raw stored values, contrasting with the "(computed)" values that may involve additional processing or mapping lookups.
Wiki pages you might want to explore:
File: src/ROSETTA/Grammar/Support.code (L5340-5354)
enum classifier
{
e_transformation = 0x1, /*!< classify as a transformation */
e_compiler_generated = 0x2, /*!< classify as compiler generated */
e_output_in_code_generation = 0x4, /*!< classify as required when generating code in unparser (orthogonal concept to transformation and compiler generated) */
e_shared = 0x8, /*!< classify as a shared IR node (part of evolving support for AST merging) */
e_frontend_specific = 0x10, /*!< classify as frontend specific (e.g. gnu compatable function from rose_edg_required_macros_and_functions.h) */
e_source_position_unavailable_in_frontend = 0x20, /*!< classify as explictly unabailable from front-end */
e_comment_or_directive = 0x40, /*!< classify as a comment or directive (not a part of the language grammar) */
e_token = 0x80, /*!< classify as a token from the parser (not a part of the language grammar) */
// DQ (4/24/2013): Added support for default arguments.
e_default_argument = 0x100,/*!< classify as a default arguement to function call expression */
// DQ (4/24/2013): Added support for implicit cast.
e_implicit_cast = 0x200 /*!< classify as a implicit cast */
};
File: src/ROSETTA/Grammar/Support.code (L5551-5552)
static const std::string& getFilenameFromID( int id );
static int getIDFromFilename( std::string filename );
File: src/ROSETTA/Grammar/Support.code (L5568-5577)
//! Access function for static datamember fileidtoname_map.
static std::map<int, std::string> & get_fileidtoname_map();
//! Access function for map of file names.
static void set_fileidtoname_map(std::map<int, std::string> & X);
// DQ (2/23/2010): Added static access function for static data members (ROSETTA generates only not statuc access functions).
//! Access function for static datamember nametofileid_map.
static std::map<std::string, int> & get_nametofileid_map();
//! Access function for map of file names.
static void set_nametofileid_map(std::map<std::string,int> & X);
File: src/ROSETTA/Grammar/Support.code (L5584-5594)
enum p_fileflags {
COPY_FILE_ID = -1, /*!< default value (equivalent to filename with "COPY") */
NULL_FILE_ID = -2, /*!< value equivalent to filename with "NULL_FILE" */
TRANSFORMATION_FILE_ID = -3, /*!< value for all nodes marked as part of a translation */
COMPILER_GENERATED_FILE_ID = -4, /*!< value for compiler generated IR nodes (NOT marked for output) */
COMPILER_GENERATED_MARKED_FOR_OUTPUT_FILE_ID = -5, /*!< value for compiler generated IR nodes (marked for output, deprecated value) */
// MK (8/2/05) : Added new enum value to facilitate interface to maps. If we try
// to retrieve the fileid for a filename which isn't in the map, we return
// BAD_FILE_ID to indicate this.
BAD_FILE_ID = -6 /*!< value returned if there is no file id mapped to given filename */
};