1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2002-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Osint; use Osint;
27 with Osint.C; use Osint.C;
29 package body Sinput.D is
31 Dfile : Source_File_Index;
32 -- Index of currently active debug source file
34 ------------------------
35 -- Close_Debug_Source --
36 ------------------------
38 procedure Close_Debug_Source is
39 S : Source_File_Record renames Source_File.Table (Dfile);
40 Src : Source_Buffer_Ptr;
43 Trim_Lines_Table (Dfile);
46 -- Now we need to read the file that we wrote and store it in memory for
50 (S.Full_Debug_Name, S.Source_First, S.Source_Last, Src);
52 end Close_Debug_Source;
54 -------------------------
55 -- Create_Debug_Source --
56 -------------------------
58 procedure Create_Debug_Source
59 (Source : Source_File_Index;
63 Loc := Source_File.Table (Source_File.Last).Source_Last + 1;
64 Source_File.Append (Source_File.Table (Source));
65 Dfile := Source_File.Last;
68 S : Source_File_Record renames Source_File.Table (Dfile);
71 S.Full_Debug_Name := Create_Debug_File (S.File_Name);
72 S.Debug_Source_Name := Strip_Directory (S.Full_Debug_Name);
73 S.Source_First := Loc;
75 S.Lines_Table := null;
76 S.Last_Source_Line := 1;
78 -- Allocate lines table, guess that it needs to be three times bigger
79 -- than the original source (in number of lines).
82 (S, Int (Source_File.Table (Source).Last_Source_Line * 3));
83 S.Lines_Table (1) := Loc;
85 end Create_Debug_Source;
87 ----------------------
88 -- Write_Debug_Line --
89 ----------------------
91 procedure Write_Debug_Line (Str : String; Loc : in out Source_Ptr) is
92 S : Source_File_Record renames Source_File.Table (Dfile);
95 -- Ignore write request if null line at start of file
97 if Str'Length = 0 and then Loc = S.Source_First then
100 -- Here we write the line, compute the source location for the following
101 -- line, allocate its table entry, and update the source record entry.
104 Write_Debug_Info (Str (Str'First .. Str'Last - 1));
105 Loc := Loc - 1 + Source_Ptr (Str'Length + Debug_File_Eol_Length);
106 Add_Line_Tables_Entry (S, Loc);
107 S.Source_Last := Loc;
108 Set_Source_File_Index_Table (Dfile);
110 end Write_Debug_Line;