diff options
| author | Tristan Gingold <tgingold@free.fr> | 2015-01-17 15:13:32 +0100 | 
|---|---|---|
| committer | Tristan Gingold <tgingold@free.fr> | 2015-01-17 15:13:32 +0100 | 
| commit | e8f6e48e092ce96cbd643a0ff94c4dafe245b9dd (patch) | |
| tree | aaccc1c570fbc8145dfd3fb149392e4e5dd6c8dd /src | |
| parent | e61c1e4dd7287ac1f71d73776a26d3100778cf47 (diff) | |
| download | ghdl-e8f6e48e092ce96cbd643a0ff94c4dafe245b9dd.tar.gz ghdl-e8f6e48e092ce96cbd643a0ff94c4dafe245b9dd.tar.bz2 ghdl-e8f6e48e092ce96cbd643a0ff94c4dafe245b9dd.zip | |
debugger: add list command.
Diffstat (limited to 'src')
| -rw-r--r-- | src/vhdl/evaluation.adb | 10 | ||||
| -rw-r--r-- | src/vhdl/simulate/debugger.adb | 135 | 
2 files changed, 126 insertions, 19 deletions
| diff --git a/src/vhdl/evaluation.adb b/src/vhdl/evaluation.adb index 82be3f311..f738c3678 100644 --- a/src/vhdl/evaluation.adb +++ b/src/vhdl/evaluation.adb @@ -3015,7 +3015,15 @@ package body Evaluation is                 Path_Add_Name (El);                 Path_Add (":");              when Iir_Kind_Generate_Statement_Body => -               Path_Add_Element (Get_Parent (El), Is_Instance); +               declare +                  Parent : constant Iir := Get_Parent (El); +               begin +                  if Get_Kind (Parent) = Iir_Kind_For_Generate_Statement then +                     Path_Instance := El; +                  else +                     Path_Add_Element (Parent, Is_Instance); +                  end if; +               end;              when Iir_Kinds_Sequential_Statement =>                 Path_Add_Element (Get_Parent (El), Is_Instance);              when others => diff --git a/src/vhdl/simulate/debugger.adb b/src/vhdl/simulate/debugger.adb index a62a54114..4bceea97b 100644 --- a/src/vhdl/simulate/debugger.adb +++ b/src/vhdl/simulate/debugger.adb @@ -49,6 +49,22 @@ package body Debugger is     --  to the prompt.     Command_Error : exception; +   --  For the list command: current file and current line. +   List_Current_File : Source_File_Entry := No_Source_File_Entry; +   List_Current_Line : Natural := 0; +   List_Current_Line_Pos : Source_Ptr := 0; + +   --  Set List_Current_* from a location.  To be called after program break +   --  to indicate current location. +   procedure Set_List_Current (Loc : Location_Type) +   is +      Offset : Natural; +   begin +      Files_Map.Location_To_Coord +        (Loc, List_Current_File, List_Current_Line_Pos, +         List_Current_Line, Offset); +   end Set_List_Current; +     Dbg_Top_Frame : Block_Instance_Acc;     Dbg_Cur_Frame : Block_Instance_Acc; @@ -838,6 +854,89 @@ package body Debugger is        New_Line;     end Disp_A_Frame; +   procedure Disp_Current_Lines +   is +      use Files_Map; +      --  Number of lines to display before and after the current line. +      Radius : constant := 5; + +      Buf : File_Buffer_Acc; + +      Pos : Source_Ptr; +      Line : Natural; +      Len : Source_Ptr; +      C : Character; +   begin +      if List_Current_Line > Radius then +         Line := List_Current_Line - Radius; +      else +         Line := 1; +      end if; + +      Pos := Line_To_Position (List_Current_File, Line); +      Buf := Get_File_Source (List_Current_File); + +      while Line < List_Current_Line + Radius loop +         --  Compute line length. +         Len := 0; +         loop +            C := Buf (Pos + Len); +            exit when C = ASCII.CR or C = ASCII.LF or C = ASCII.NUL; +            Len := Len + 1; +         end loop; + +         --  Disp line number. +         declare +            Str : constant String := Natural'Image (Line); +         begin +            if Line = List_Current_Line then +               Put ('*'); +            else +               Put (' '); +            end if; +            Put ((Str'Length .. 5 => ' ')); +            Put (Str (Str'First + 1 .. Str'Last)); +            Put (' '); +         end; + +         --  Disp line. +         Put_Line (String (Buf (Pos .. Pos + Len - 1))); + +         --  Skip EOL. +         exit when C = ASCII.NUL; +         Pos := Pos + Len + 1; +         if C = ASCII.CR then +            if Buf (Pos) = ASCII.LF then +               Pos := Pos + 1; +            end if; +         else +            pragma Assert (C = ASCII.LF); +            if Buf (Pos) = ASCII.CR then +               Pos := Pos + 1; +            end if; +         end if; + +         Line := Line + 1; +      end loop; +   end Disp_Current_Lines; + +   procedure Disp_Source_Line (Loc : Location_Type) +   is +      use Files_Map; + +      File : Source_File_Entry; +      Line_Pos : Source_Ptr; +      Line : Natural; +      Offset : Natural; +      Buf : File_Buffer_Acc; +      Next_Line_Pos : Source_Ptr; +   begin +      Location_To_Coord (Loc, File, Line_Pos, Line, Offset); +      Buf := Get_File_Source (File); +      Next_Line_Pos := Line_To_Position (File, Line + 1); +      Put (String (Buf (Line_Pos .. Next_Line_Pos - 1))); +   end Disp_Source_Line; +     type Menu_Kind is (Menu_Command, Menu_Submenu);     type Menu_Entry (Kind : Menu_Kind);     type Menu_Entry_Acc is access all Menu_Entry; @@ -903,6 +1002,13 @@ package body Debugger is        end loop;     end Ps_Proc; +   procedure List_Proc (Line : String) +   is +      pragma Unreferenced (Line); +   begin +      Disp_Current_Lines; +   end List_Proc; +     procedure Up_Proc (Line : String)     is        pragma Unreferenced (Line); @@ -1515,10 +1621,16 @@ package body Debugger is        Next => Menu_Info_Signals'Access,        Proc => Info_Proc_Proc'Access); +   Menu_List : aliased Menu_Entry := +     (Kind => Menu_Command, +      Name => new String'("l*list"), +      Next => null, +      Proc => List_Proc'Access); +     Menu_Down : aliased Menu_Entry :=       (Kind => Menu_Command,        Name => new String'("down"), -      Next => null, +      Next => Menu_List'Access,        Proc => Down_Proc'Access);     Menu_Up : aliased Menu_Entry := @@ -1696,23 +1808,6 @@ package body Debugger is        end loop;     end Help_Proc; -   procedure Disp_Source_Line (Loc : Location_Type) -   is -      use Files_Map; - -      File : Source_File_Entry; -      Line_Pos : Source_Ptr; -      Line : Natural; -      Offset : Natural; -      Buf : File_Buffer_Acc; -      Next_Line_Pos : Source_Ptr; -   begin -      Location_To_Coord (Loc, File, Line_Pos, Line, Offset); -      Buf := Get_File_Source (File); -      Next_Line_Pos := Line_To_Position (File, Line + 1); -      Put (String (Buf (Line_Pos .. Next_Line_Pos - 1))); -   end Disp_Source_Line; -     function Breakpoint_Hit return Natural     is        Stmt : constant Iir := Current_Process.Instance.Stmt; @@ -1794,6 +1889,10 @@ package body Debugger is              Put_Line ("error occurred, enterring in debugger");        end case; +      if Dbg_Cur_Frame /= null then +         Set_List_Current (Get_Location (Dbg_Cur_Frame.Stmt)); +      end if; +        Command_Status := Status_Default;        loop | 
