Skip to content

Commit

Permalink
MIEngine: Convert TargetId to string
Browse files Browse the repository at this point in the history
Convert TargetId field to string and remove all parsing logic.
This way, the unique global ID is stored in Id and target specific
target-id is stored in its string format. Stopped events fetch global ID
for thread identification.

This fix should also address [issue 1448](microsoft#1448).

Signed-off-by: intel-rganesh rakesh.ganesh@intel.com
  • Loading branch information
intel-rganesh committed Jul 19, 2024
1 parent b8bfa53 commit 84e9db6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 59 deletions.
4 changes: 2 additions & 2 deletions src/MIDebugEngine/AD7.Impl/AD7Thread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ int IDebugThread2.GetProgram(out IDebugProgram2 program)
// Gets the system thread identifier.
int IDebugThread2.GetThreadId(out uint threadId)
{
threadId = _debuggedThread.TargetId;
threadId = (uint)_debuggedThread.Id;
return Constants.S_OK;
}

Expand All @@ -222,7 +222,7 @@ int IDebugThread2.GetThreadProperties(enum_THREADPROPERTY_FIELDS dwFields, THREA

if ((dwFields & enum_THREADPROPERTY_FIELDS.TPF_ID) != 0)
{
props.dwThreadId = _debuggedThread.TargetId;
props.dwThreadId = (uint)_debuggedThread.Id;
props.dwFields |= enum_THREADPROPERTY_FIELDS.TPF_ID;
}
if ((dwFields & enum_THREADPROPERTY_FIELDS.TPF_SUSPENDCOUNT) != 0)
Expand Down
61 changes: 4 additions & 57 deletions src/MIDebugEngine/Engine.Impl/DebuggedThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;

Expand All @@ -17,14 +18,14 @@ public DebuggedThread(int id, MIDebugEngine.AD7Engine engine)
{
Id = id;
Name = "";
TargetId = (uint)id;
TargetId = id.ToString(CultureInfo.InvariantCulture);
AD7Thread ad7Thread = new MIDebugEngine.AD7Thread(engine, this);
Client = ad7Thread;
ChildThread = false;
}

public int Id { get; private set; }
public uint TargetId { get; set; }
public string TargetId { get; set; }
public Object Client { get; private set; } // really AD7Thread
public bool Alive { get; set; }
public bool Default { get; set; }
Expand Down Expand Up @@ -331,58 +332,8 @@ private ThreadContext CreateContext(TupleValue frame)
return new ThreadContext(pc, textPosition, func, level, from);
}

private bool TryGetTidFromTargetId(string targetId, out uint tid)
{
tid = 0;
if (System.UInt32.TryParse(targetId, out tid) && tid != 0)
{
return true;
}
else if (targetId.StartsWith("Thread ", StringComparison.OrdinalIgnoreCase) &&
System.UInt32.TryParse(targetId.Substring("Thread ".Length), out tid) &&
tid != 0
)
{
return true;
}
else if (targetId.StartsWith("Process ", StringComparison.OrdinalIgnoreCase) &&
System.UInt32.TryParse(targetId.Substring("Process ".Length), out tid) &&
tid != 0
)
{ // First thread in a linux process has tid == pid
return true;
}
else if (targetId.StartsWith("Thread ", StringComparison.OrdinalIgnoreCase))
{
// In processes with pthreads the thread name is in form: "Thread <0x123456789abc> (LWP <thread-id>)"
int lwp_pos = targetId.IndexOf("(LWP ", StringComparison.Ordinal);
int paren_pos = targetId.LastIndexOf(')');
int len = paren_pos - (lwp_pos + 5);
if (len > 0 && System.UInt32.TryParse(targetId.Substring(lwp_pos + 5, len), out tid) && tid != 0)
{
return true;
}
}
else if (targetId.StartsWith("LWP ", StringComparison.OrdinalIgnoreCase) &&
System.UInt32.TryParse(targetId.Substring("LWP ".Length), out tid) &&
tid != 0
)
{
// In gdb coredumps the thread name is in the form:" LWP <thread-id>"
return true;
}
else
{
tid = --s_targetId;
return true;
}

return false;
}

private DebuggedThread SetThreadInfoFromResultValue(ResultValue resVal, out bool isNewThread)
{
isNewThread = false;
int threadId = resVal.FindInt("id");
string targetId = resVal.TryFindString("target-id");

Expand All @@ -392,11 +343,7 @@ private DebuggedThread SetThreadInfoFromResultValue(ResultValue resVal, out bool
// Only update targetId if it is a new thread.
if (isNewThread && !String.IsNullOrEmpty(targetId))
{
uint tid = 0;
if (TryGetTidFromTargetId(targetId, out tid))
{
thread.TargetId = tid;
}
thread.TargetId = targetId;
}
if (resVal.Contains("name"))
{
Expand Down

0 comments on commit 84e9db6

Please sign in to comment.