@@ -52,16 +52,18 @@ u32 plugin_is_GPL_compatible;
52
52
W(Cdr, cdr) \
53
53
W(VecFunc, vector) \
54
54
W(ListFunc, list) \
55
- W(DeleteProcess, delete-process) \
55
+ W(Set, set) \
56
56
W(Eval, eval) \
57
+ W(Eq, eq) \
58
+ W(DeleteProcess, delete-process) \
57
59
\
58
60
W(GdbCmd, gdb--command) \
59
61
W(ExtractContext, gdb--extract-context) \
60
- W(SetData, gdb--set-data) \
61
62
W(Error, error) \
62
63
W(LogError, gdb--log-error) \
63
64
\
64
- W(FinalizeUserCmd, gdb--finalize-user-command) \
65
+ W(GdbData, gdb--data) \
66
+ W(ConsoleOutputToData, to-data) \
65
67
W(OmitConsoleOutput, gdb--omit-console-output) \
66
68
\
67
69
W(SwitchToThread, gdb--switch-to-thread) \
@@ -254,6 +256,14 @@ static inline emacs_value internFuncall(emacs_env *Env, char *Func, u32 NumArgs,
254
256
return Result ;
255
257
}
256
258
259
+ static inline bool isNil (emacs_env * Env , emacs_value Thing ) {
260
+ return !Env -> is_not_nil (Env , Thing );
261
+ }
262
+
263
+ static inline bool isNotNil (emacs_env * Env , emacs_value Thing ) {
264
+ return Env -> is_not_nil (Env , Thing );
265
+ }
266
+
257
267
static void breakpointChange (emacs_env * Env , mi_result * Breakpoint ) {
258
268
#define breakpointVariablesWriter (W ) W(Number, number), \
259
269
W(Type, type), \
@@ -652,7 +662,7 @@ static void logError(emacs_env *Env, mi_result *Result, char **PrintString, char
652
662
if (Message ) {
653
663
bufPrintf (* PrintString , "%s\n(gdb) " , Result -> variant .cstring );
654
664
funcall (Env , LogError , 1 , (emacs_value []){getEmacsString (Env , Message )});
655
- funcall (Env , FinalizeUserCmd , 0 , 0 );
665
+ funcall (Env , Set , 2 , ( emacs_value []){ OmitConsoleOutput , T } );
656
666
}
657
667
}
658
668
@@ -748,13 +758,35 @@ static void handleMiOobRecord(emacs_env *Env, mi_oob_record *Record, char **Prin
748
758
mi_stream_record * StreamRecord = Record -> variant .stream_record ;
749
759
switch (StreamRecord -> kind ) {
750
760
case GDBWIRE_MI_CONSOLE : {
751
- if (!Env -> is_not_nil (Env , funcall (Env , Eval , 1 , (emacs_value []){OmitConsoleOutput }))) {
761
+ emacs_value Omit = funcall (Env , Eval , 1 , (emacs_value []){OmitConsoleOutput });
762
+ if (isNil (Env , funcall (Env , Eval , 1 , (emacs_value []){OmitConsoleOutput }))) {
752
763
bufPrintf (* PrintString , "%s" , StreamRecord -> cstring );
753
764
}
765
+ else if (funcall (Env , Eq , 2 , (emacs_value []){Omit , ConsoleOutputToData })) {
766
+ emacs_value * Array = 0 ;
767
+
768
+ emacs_value UserPtr = funcall (Env , Eval , 1 , (emacs_value []){GdbData });
769
+ bool UserPtrExists = isNotNil (Env , UserPtr );
770
+ if (UserPtrExists ) {
771
+ Array = Env -> get_user_ptr (Env , UserPtr );
772
+ }
773
+
774
+ if (StreamRecord -> cstring ) {
775
+ // NOTE(nox): Remove newlines
776
+ StreamRecord -> cstring [strlen (StreamRecord -> cstring ) - 1 ] = 0 ;
777
+ }
778
+ bufPush (Array , getEmacsString (Env , StreamRecord -> cstring ));
779
+ if (UserPtrExists ) {
780
+ Env -> set_user_ptr (Env , UserPtr , Array );
781
+ }
782
+ else {
783
+ UserPtr = Env -> make_user_ptr (Env , 0 , Array );
784
+ funcall (Env , Set , 2 , (emacs_value []){GdbData , UserPtr });
785
+ }
786
+ }
754
787
} break ;
755
788
756
789
case GDBWIRE_MI_TARGET : {
757
- // TODO(nox): If we are outputting to another tty, will we ever receive this?
758
790
bufPrintf (* PrintString , "Target: %s" , StreamRecord -> cstring );
759
791
} break ;
760
792
@@ -786,6 +818,7 @@ typedef struct token_context {
786
818
Context_Disassemble ,
787
819
Context_PersistThread ,
788
820
Context_GetData ,
821
+ Context_GetConsoleData ,
789
822
Context_IgnoreErrors ,
790
823
791
824
Context_Size ,
@@ -901,7 +934,21 @@ static void handleMiResultRecord(emacs_env *Env, mi_result_record *Record, char
901
934
char * String = getResultString (Result , Key );
902
935
free (Key );
903
936
904
- funcall (Env , SetData , 1 , (emacs_value []){getEmacsString (Env , String )});
937
+ funcall (Env , Set , 2 , (emacs_value []){GdbData , getEmacsString (Env , String )});
938
+ } break ;
939
+
940
+ case Context_GetConsoleData : {
941
+ emacs_value UserPtr = funcall (Env , Eval , 1 , (emacs_value []){GdbData });
942
+ if (isNotNil (Env , UserPtr )) {
943
+ emacs_value * Array = Env -> get_user_ptr (Env , UserPtr );
944
+ emacs_value List = funcall (Env , ListFunc , bufLen (Array ), Array );
945
+ bufFree (Array );
946
+ funcall (Env , Set , 2 , (emacs_value []){GdbData , List });
947
+ } else {
948
+ funcall (Env , Set , 2 , (emacs_value []){GdbData , T });
949
+ }
950
+
951
+ funcall (Env , Set , 2 , (emacs_value []){OmitConsoleOutput , T });
905
952
} break ;
906
953
907
954
ignoreDefaultCase ();
@@ -914,8 +961,19 @@ static void handleMiResultRecord(emacs_env *Env, mi_result_record *Record, char
914
961
ignoreCase (Context_IgnoreErrors );
915
962
916
963
case Context_GetData : {
964
+ emacs_value UserPtr = funcall (Env , Eval , 1 , (emacs_value []){GdbData });
965
+ if (isNotNil (Env , UserPtr )) {
966
+ emacs_value * Array = Env -> get_user_ptr (Env , UserPtr );
967
+ bufFree (Array );
968
+ }
969
+ funcall (Env , Set , 2 , (emacs_value []){GdbData , Error });
970
+ funcall (Env , Set , 2 , (emacs_value []){OmitConsoleOutput , T });
971
+ logError (Env , Result , PrintString , "msg" );
972
+ } break ;
973
+
974
+ case Context_GetConsoleData : {
975
+ funcall (Env , Set , 2 , (emacs_value []){GdbData , Error });
917
976
logError (Env , Result , PrintString , "msg" );
918
- funcall (Env , SetData , 1 , & Error );
919
977
} break ;
920
978
921
979
default : { logError (Env , Result , PrintString , "msg" ); } break ;
@@ -963,9 +1021,9 @@ static emacs_value handleGdbMiOutput(emacs_env *Env, ptrdiff_t NumberOfArgs,
963
1021
} break ;
964
1022
965
1023
case GDBWIRE_MI_OUTPUT_PROMPT : {
966
- if (! Env -> is_not_nil (Env , funcall (Env , Eval , 1 , (emacs_value []){OmitConsoleOutput }))) {
1024
+ if (isNil (Env , funcall (Env , Eval , 1 , (emacs_value []){OmitConsoleOutput }))) {
967
1025
bufPrintf (PrintString , "(gdb) " );
968
- funcall (Env , FinalizeUserCmd , 0 , 0 );
1026
+ funcall (Env , Set , 2 , ( emacs_value []){ OmitConsoleOutput , T } );
969
1027
}
970
1028
} break ;
971
1029
}
0 commit comments