1212using System . Threading . Tasks ;
1313using System . Text . RegularExpressions ;
1414using System . Globalization ;
15+ using Microsoft . VisualStudio . Debugger . Interop . DAP ;
1516
1617namespace Microsoft . MIDebugEngine
1718{
@@ -32,7 +33,7 @@ internal interface IVariableInformation : IDisposable
3233 void EnsureChildren ( ) ;
3334 void AsyncEval ( IDebugEventCallback2 pExprCallback ) ;
3435 void AsyncError ( IDebugEventCallback2 pExprCallback , IDebugProperty2 error ) ;
35- void SyncEval ( enum_EVALFLAGS dwFlags = 0 ) ;
36+ void SyncEval ( enum_EVALFLAGS dwFlags = 0 , DAPEvalFlags dwDAPFlags = 0 ) ;
3637 ThreadContext ThreadContext { get ; }
3738 VariableInformation FindChildByName ( string name ) ;
3839 string EvalDependentExpression ( string expr ) ;
@@ -399,11 +400,11 @@ public void AsyncError(IDebugEventCallback2 pExprCallback, IDebugProperty2 error
399400 AsyncErrorImpl ( pExprCallback != null ? new EngineCallback ( _engine , pExprCallback ) : _engine . Callback , this , error ) ;
400401 }
401402
402- public void SyncEval ( enum_EVALFLAGS dwFlags = 0 )
403+ public void SyncEval ( enum_EVALFLAGS dwFlags = 0 , DAPEvalFlags dwDAPFlags = 0 )
403404 {
404405 Task eval = Task . Run ( async ( ) =>
405406 {
406- await Eval ( dwFlags ) ;
407+ await Eval ( dwFlags , dwDAPFlags ) ;
407408 } ) ;
408409 eval . Wait ( ) ;
409410 }
@@ -444,7 +445,7 @@ private bool IsConsoleExecCmd(string command, out string strippedCommand)
444445 return false ;
445446 }
446447
447- internal async Task Eval ( enum_EVALFLAGS dwFlags = 0 )
448+ internal async Task Eval ( enum_EVALFLAGS dwFlags = 0 , DAPEvalFlags dwDAPFlags = 0 )
448449 {
449450 this . VerifyNotDisposed ( ) ;
450451
@@ -469,6 +470,22 @@ internal async Task Eval(enum_EVALFLAGS dwFlags = 0)
469470 }
470471 else
471472 {
473+ bool canRunClipboardContextCommands = this . _debuggedProcess . MICommandFactory . Mode == MIMode . Gdb && dwDAPFlags . HasFlag ( DAPEvalFlags . CLIPBOARD_CONTEXT ) ;
474+ int numElements = 200 ;
475+
476+ if ( canRunClipboardContextCommands )
477+ {
478+ string showPrintElementsResult = await MIDebugCommandDispatcher . ExecuteCommand ( "show print elements" , _debuggedProcess , ignoreFailures : true ) ;
479+ // Possible values for 'numElementsStr'
480+ // "Limit on string chars or array elements to print is <number>."
481+ // "Limit on string chars or array elements to print is unlimited."
482+ string numElementsStr = Regex . Match ( showPrintElementsResult , @"\d+" ) . Value ;
483+ if ( ! string . IsNullOrEmpty ( numElementsStr ) && int . TryParse ( numElementsStr , out numElements ) && numElements != 0 )
484+ {
485+ await MIDebugCommandDispatcher . ExecuteCommand ( "set print elements 0" , _debuggedProcess , ignoreFailures : true ) ;
486+ }
487+ }
488+
472489 int threadId = Client . GetDebuggedThread ( ) . Id ;
473490 uint frameLevel = _ctx . Level ;
474491 Results results = await _engine . DebuggedProcess . MICommandFactory . VarCreate ( _strippedName , threadId , frameLevel , dwFlags , ResultClass . None ) ;
@@ -522,7 +539,7 @@ internal async Task Eval(enum_EVALFLAGS dwFlags = 0)
522539 }
523540 else
524541 {
525- Debug . Fail ( "Weird msg from -var-evaluate-expression" ) ;
542+ Debug . Fail ( "Unexpected format of msg from -var-evaluate-expression" ) ;
526543 }
527544 }
528545 }
@@ -533,7 +550,12 @@ internal async Task Eval(enum_EVALFLAGS dwFlags = 0)
533550 }
534551 else
535552 {
536- Debug . Fail ( "Weird msg from -var-create" ) ;
553+ Debug . Fail ( "Unexpected format of msg from -var-create" ) ;
554+ }
555+
556+ if ( canRunClipboardContextCommands && numElements != 0 )
557+ {
558+ await MIDebugCommandDispatcher . ExecuteCommand ( string . Format ( CultureInfo . InvariantCulture , "set print elements {0}" , numElements ) , _debuggedProcess , ignoreFailures : true ) ;
537559 }
538560 }
539561 }
@@ -570,7 +592,7 @@ internal async Task Format()
570592 }
571593 else
572594 {
573- Debug . Fail ( "Weird msg from expression formatting" ) ;
595+ Debug . Fail ( "Unexpected format of msg from expression formatting" ) ;
574596 }
575597 }
576598
0 commit comments