Skip to content

Commit da0ec2f

Browse files
committed
Merge branch '22-dap-integration-3' into 'master'
DAP python API See merge request eng/ide/gnatstudio!114
2 parents a166a0d + e57abc0 commit da0ec2f

File tree

3 files changed

+127
-36
lines changed

3 files changed

+127
-36
lines changed

dap/src/dap-clients.adb

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ package body DAP.Clients is
9191
New_Request : in out DAP.Requests.DAP_Request_Access);
9292

9393
-- Evaluate_Request --
94-
type Evaluate_Kind is
95-
(Show_Lang, Set_Lang, Restore_Lang, List_Adainit,
96-
Info_Line, Info_First_Line, Hover, Variable_Address, Endian);
94+
9795
type Evaluate_Request is
9896
new DAP.Requests.Evaluate.Evaluate_DAP_Request
9997
with record
@@ -1454,20 +1452,47 @@ package body DAP.Clients is
14541452
Trace (Me, E);
14551453
end Process_Event;
14561454

1455+
--------------------------
1456+
-- Process_User_Command --
1457+
--------------------------
1458+
1459+
procedure Process_User_Command
1460+
(Self : in out DAP_Client;
1461+
Cmd : String;
1462+
Output_Command : Boolean := False)
1463+
is
1464+
Request : DAP.Requests.DAP_Request_Access;
1465+
begin
1466+
if Output_Command then
1467+
Self.Display_In_Debugger_Console (Cmd, Is_Command => True);
1468+
end if;
1469+
1470+
Request := Self.Create_Evaluate_Command
1471+
(Command, VSS.Strings.Conversions.To_Virtual_String (Cmd));
1472+
1473+
Self.Enqueue (Request);
1474+
end Process_User_Command;
1475+
14571476
---------------------------------
14581477
-- Display_In_Debugger_Console --
14591478
---------------------------------
14601479

14611480
procedure Display_In_Debugger_Console
1462-
(Self : in out DAP_Client;
1463-
Msg : String)
1481+
(Self : in out DAP_Client;
1482+
Msg : String;
1483+
Is_Command : Boolean := False)
14641484
is
14651485
Console : constant access Interactive_Console_Record'Class :=
14661486
DAP.Views.Consoles.Get_Debugger_Interactive_Console (Self);
14671487

14681488
begin
14691489
if Console /= null then
1470-
Console.Insert (Msg, Add_LF => True);
1490+
if Is_Command then
1491+
Console.Insert
1492+
(Msg, Add_LF => True, Highlight => True, Add_To_History => True);
1493+
else
1494+
Console.Insert (Msg, Add_LF => True);
1495+
end if;
14711496
end if;
14721497
end Display_In_Debugger_Console;
14731498

@@ -1823,6 +1848,32 @@ package body DAP.Clients is
18231848
Self.Enqueue (DAP.Requests.DAP_Request_Access (Req));
18241849
end Value_Of;
18251850

1851+
-----------------------------
1852+
-- Create_Evaluate_Command --
1853+
-----------------------------
1854+
1855+
function Create_Evaluate_Command
1856+
(Self : DAP_Client;
1857+
Kind : Evaluate_Kind;
1858+
Cmd : Virtual_String)
1859+
return DAP.Requests.DAP_Request_Access
1860+
is
1861+
Req : constant Evaluate_Request_Access :=
1862+
new Evaluate_Request (Self.Kernel);
1863+
Frame : constant Integer := Self.Get_Selected_Frame;
1864+
begin
1865+
Req.Kind := Kind;
1866+
Req.Client := Self.This;
1867+
Req.Parameters.arguments.expression := Cmd;
1868+
if Frame /= 0 then
1869+
Req.Parameters.arguments.frameId :=
1870+
(Is_Set => True, Value => Frame);
1871+
end if;
1872+
Req.Parameters.arguments.context :=
1873+
(Is_Set => True, Value => DAP.Tools.Enum.repl);
1874+
return DAP.Requests.DAP_Request_Access (Req);
1875+
end Create_Evaluate_Command;
1876+
18261877
-----------------------
18271878
-- On_Result_Message --
18281879
-----------------------
@@ -1832,33 +1883,11 @@ package body DAP.Clients is
18321883
Result : in out DAP.Tools.EvaluateResponse;
18331884
New_Request : in out DAP.Requests.DAP_Request_Access)
18341885
is
1835-
procedure Command (Kind : Evaluate_Kind; Cmd : Virtual_String);
18361886
procedure Show_File
18371887
(File : Virtual_String;
18381888
Line : Natural;
18391889
Addr : Address_Type);
18401890

1841-
-------------
1842-
-- Command --
1843-
-------------
1844-
1845-
procedure Command (Kind : Evaluate_Kind; Cmd : Virtual_String) is
1846-
Req : constant Evaluate_Request_Access :=
1847-
new Evaluate_Request (Self.Kernel);
1848-
Frame : constant Integer := Self.Client.Get_Selected_Frame;
1849-
begin
1850-
Req.Kind := Kind;
1851-
Req.Client := Self.Client;
1852-
Req.Parameters.arguments.expression := Cmd;
1853-
if Frame /= 0 then
1854-
Req.Parameters.arguments.frameId :=
1855-
(Is_Set => True, Value => Frame);
1856-
end if;
1857-
Req.Parameters.arguments.context :=
1858-
(Is_Set => True, Value => DAP.Tools.Enum.repl);
1859-
New_Request := DAP.Requests.DAP_Request_Access (Req);
1860-
end Command;
1861-
18621891
---------------
18631892
-- Show_File --
18641893
---------------
@@ -1898,7 +1927,8 @@ package body DAP.Clients is
18981927
then Match.Captured (1)
18991928
else "auto");
19001929
end;
1901-
Command (Endian, "show endian");
1930+
New_Request := Self.Client.Create_Evaluate_Command
1931+
(Endian, "show endian");
19021932

19031933
when Endian =>
19041934
declare
@@ -1911,17 +1941,21 @@ package body DAP.Clients is
19111941
Match := Endian_Pattern.Match (Result.a_body.result);
19121942
end;
19131943

1914-
Command (Set_Lang, "set lang c");
1944+
New_Request := Self.Client.Create_Evaluate_Command
1945+
(Set_Lang, "set lang c");
19151946

19161947
when Set_Lang =>
1917-
Command (List_Adainit, "list adainit");
1948+
New_Request := Self.Client.Create_Evaluate_Command
1949+
(List_Adainit, "list adainit");
19181950

19191951
when List_Adainit =>
1920-
Command (Restore_Lang, "set lang " & Self.Client.Stored_Lang);
1952+
New_Request := Self.Client.Create_Evaluate_Command
1953+
(Restore_Lang, "set lang " & Self.Client.Stored_Lang);
19211954

19221955
when Restore_Lang =>
19231956
if DAP.Modules.Preferences.Open_Main_Unit.Get_Pref then
1924-
Command (Info_Line, "info line");
1957+
New_Request := Self.Client.Create_Evaluate_Command
1958+
(Info_Line, "info line");
19251959
else
19261960
Self.Client.On_Ready;
19271961
end if;
@@ -1948,7 +1982,7 @@ package body DAP.Clients is
19481982
if Match.Has_Match
19491983
and then Match.Has_Capture (1)
19501984
then
1951-
Command
1985+
New_Request := Self.Client.Create_Evaluate_Command
19521986
(Info_First_Line, "info line "
19531987
& Match.Captured (1) & ":1");
19541988
else
@@ -1993,6 +2027,9 @@ package body DAP.Clients is
19932027
(Self.Kernel, "0" & S (Index .. S'Last));
19942028
end if;
19952029
end;
2030+
2031+
when Command =>
2032+
null;
19962033
end case;
19972034
end On_Result_Message;
19982035

dap/src/dap-clients.ads

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,11 @@ package DAP.Clients is
290290
return DAP.Tools.Optional_Capabilities;
291291

292292
procedure Display_In_Debugger_Console
293-
(Self : in out DAP_Client;
294-
Msg : String);
293+
(Self : in out DAP_Client;
294+
Msg : String;
295+
Is_Command : Boolean := False);
296+
-- Displays the message in the console. Highlight it and add to the
297+
-- history if Is_Command is True
295298

296299
procedure Show_Breakpoints (Self : DAP_Client);
297300

@@ -316,6 +319,13 @@ package DAP.Clients is
316319
Bt : Backtrace_Vectors.Vector);
317320
-- Update backtrace information
318321

322+
procedure Process_User_Command
323+
(Self : in out DAP_Client;
324+
Cmd : String;
325+
Output_Command : Boolean := False);
326+
-- Execute the debugger command. Print the command in the console
327+
-- if Output_Command is True
328+
319329
-- DAP_Visual_Debugger --
320330

321331
overriding function Get_Num
@@ -471,4 +481,14 @@ private
471481
Line : out Natural;
472482
Addr : out DAP.Types.Address_Type);
473483

484+
type Evaluate_Kind is
485+
(Show_Lang, Set_Lang, Restore_Lang, List_Adainit,
486+
Info_Line, Info_First_Line, Hover, Variable_Address, Endian, Command);
487+
488+
function Create_Evaluate_Command
489+
(Self : DAP_Client;
490+
Kind : Evaluate_Kind;
491+
Cmd : VSS.Strings.Virtual_String)
492+
return DAP.Requests.DAP_Request_Access;
493+
474494
end DAP.Clients;

dap/src/modules/dap-modules-scripts.adb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,25 @@ package body DAP.Modules.Scripts is
247247
DAP.Module.Start_Program (Kernel, Visual.Client);
248248
end if;
249249

250+
elsif Command = "send" then
251+
Inst := Nth_Arg (Data, 1, New_Class (Kernel, "Debugger"));
252+
Visual := DAP_Visual_Debugger_Access
253+
(Glib.Object.GObject'(Get_Data (Inst)));
254+
255+
Visual.Client.Process_User_Command
256+
(Nth_Arg (Data, 2), Nth_Arg (Data, 3, True));
257+
258+
if not Nth_Arg (Data, 4, False) then
259+
Data.Set_Return_Value (String'("Result is not supported in DAP"));
260+
end if;
261+
262+
elsif Command = "non_blocking_send" then
263+
Inst := Nth_Arg (Data, 1, New_Class (Kernel, "Debugger"));
264+
Visual := DAP_Visual_Debugger_Access
265+
(Glib.Object.GObject'(Get_Data (Inst)));
266+
Visual.Client.Process_User_Command
267+
(Nth_Arg (Data, 2), Nth_Arg (Data, 3, True));
268+
250269
elsif Command = "close" then
251270
Inst := Nth_Arg (Data, 1, New_Class (Kernel, "Debugger"));
252271
Visual := DAP_Visual_Debugger_Access
@@ -412,6 +431,21 @@ package body DAP.Modules.Scripts is
412431
("start",
413432
Handler => Shell_Handler'Access,
414433
Class => Class);
434+
Kernel.Scripts.Register_Command
435+
("send",
436+
Params =>
437+
(1 => Param ("cmd"),
438+
2 => Param ("output", Optional => True),
439+
3 => Param ("show_in_console", Optional => True)),
440+
Handler => Shell_Handler'Access,
441+
Class => Class);
442+
Kernel.Scripts.Register_Command
443+
("non_blocking_send",
444+
Params =>
445+
(1 => Param ("cmd"),
446+
2 => Param ("output", Optional => True)),
447+
Handler => Shell_Handler'Access,
448+
Class => Class);
415449
Kernel.Scripts.Register_Command
416450
("close",
417451
Handler => Shell_Handler'Access,

0 commit comments

Comments
 (0)