Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIEngine: Convert TargetId to string #1459

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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