Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Enable objsize in lldb and SOS debugger
  • Loading branch information
Therzok committed Jul 14, 2022
commit e126005dfc6db2b7ec585e8eb8668d419bd69f27
5 changes: 3 additions & 2 deletions documentation/sos-debugging-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ importance. Shortcut names for popular functions are listed in parenthesis. Type
DumpHeap (dumpheap) DumpStack (dumpstack)
DumpVC EEStack (eestack)
GCRoot (gcroot) CLRStack (clrstack)
PrintException (pe) GCInfo
EHInfo
ObjSize GCInfo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add (objsize) after ObjSize.

PrintException (pe) EHInfo
bpmd (bpmd)

Examining CLR data structures Diagnostic Utilities
Expand Down Expand Up @@ -110,6 +110,7 @@ importance. Shortcut names for popular functions are listed in parenthesis. Type
|**HistRoot** *\<root>*|Displays information related to both promotions and relocations of the specified root.<br /><br /> The root value can be used to track the movement of an object through the garbage collections.|
|**IP2MD** (**ip2md**) \<*Code address*>|Displays the `MethodDesc` structure at the specified address in code that has been JIT-compiled.|
|**Name2EE** (**name2ee**) \<*module name*> \<*type or method name*><br /><br /> -or-<br /><br /> **Name2EE** \<*module name*>**!**\<*type or method name*>|Displays the `MethodTable` structure and `EEClass` structure for the specified type or method in the specified module.<br /><br /> The specified module must be loaded in the process.<br /><br /> To get the proper type name you can browse the module by using the an IL reflection tool like Ildasm or ILSpy. You can also pass `*` as the module name parameter to search all loaded managed modules. The *module name* parameter can also be the debugger's name for a module, such as `mscorlib` or `image00400000`.<br /><br /> This command supports the Windows debugger syntax of <`module`>`!`<`type`>. The type must be fully qualified.|
|**ObjSize** [\<*Object address*>] &#124; [**-aggregate**] [**-stat**]|Displays the size of the specified object. If you do not specify any parameters, the **ObjSize** command displays the size of all objects found on managed threads, displays all garbage collector handles in the process, and totals the size of any objects pointed to by those handles. The **ObjSize** command includes the size of all child objects in addition to the parent.<br /><br /> The **-aggregate** option can be used in conjunction with the **-stat** argument to get a detailed view of the types that are still rooted. By using **!dumpheap -stat** and **!objsize -aggregate -stat**, you can determine which objects are no longer rooted and diagnose various memory issues.|
|**PrintException** [**-nested**] [**-lines**] [\<*Exception object address*>]<br /><br /> -or-<br /><br /> **PE** [**-nested**] [\<*Exception object address*>]|Displays and formats fields of any object derived from the <xref:System.Exception> class at the specified address. If you do not specify an address, the **PrintException** command displays the last exception thrown on the current thread.<br /><br /> The **-nested** option displays details about nested exception objects.<br /><br /> The **-lines** option displays source information, if available.<br /><br /> You can use this command to format and view the `_stackTrace` field, which is a binary array.|
|**SyncBlk** [**-all** &#124; \<*syncblk number*>]|Displays the specified `SyncBlock` structure or all `SyncBlock` structures. If you do not pass any arguments, the **SyncBlk** command displays the `SyncBlock` structure corresponding to objects that are owned by a thread.<br /><br /> A `SyncBlock` structure is a container for extra information that does not need to be created for every object. It can hold COM interop data, hash codes, and locking information for thread-safe operations.|
|**SOSFlush**|Flushes an internal SOS cache.|
Expand Down
1 change: 1 addition & 0 deletions src/SOS/Strike/sos_unixexports.src
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ HistStats
IP2MD
logging
Name2EE
ObjectSize
PrintException
PathTo
StopOnCatch
Expand Down
41 changes: 40 additions & 1 deletion src/SOS/Strike/sosdocsunix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ DumpHeap (dumpheap) EEStack (eestack)
DumpVC ClrStack (clrstack)
FinalizeQueue (finalizequeue) GCInfo
GCRoot (gcroot) EHInfo
PrintException (pe) bpmd (bpmd)
ObjSize bpmd (bpmd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put (objsize) after ObjSize? This indicates that on lldb/dotnet-dump that the lowercase alias is available.

PrintException (pe)

Examining CLR data structures Diagnostic Utilities
----------------------------- -----------------------------
Expand Down Expand Up @@ -487,6 +488,44 @@ objects, there is a -nostacks option.
The -all option forces all roots to be displayed instead of just the unique roots.
\\

COMMAND: objsize.
ObjSize [<Object address>]

With no parameters, ObjSize lists the size of all objects found on managed
threads. It also enumerates all GCHandles in the process, and totals the size
of any objects pointed to by those handles. In calculating object size,
ObjSize includes the size of all child objects in addition to the parent.

For example, DumpObj lists a size of 20 bytes for this Customer object:

(lldb) dumpobj a79d40
Name: Customer
MethodTable: 009038ec
EEClass: 03ee1b84
Size: 20(0x14) bytes
(C:\pub\unittest.exe)
Fields:
MT Field Offset Type Attr Value Name
009038ec 4000008 4 CLASS instance 00a79ce4 name
009038ec 4000009 8 CLASS instance 00a79d2c bank
009038ec 400000a c System.Boolean instance 1 valid

but ObjSize lists 152 bytes:

(lldb) ObjSize a79d40
sizeof(00a79d40) = 152 ( 0x98) bytes (Customer)

This is because a Customer points to a Bank, has a name, and the Bank points to
an Address string. You can use ObjSize to identify any particularly large
objects, such as a managed cache in a web server.

While running ObjSize with no arguments may point to specific roots that hold
onto large amounts of memory it does not provide information regarding the
amount of managed memory that is still alive. This is due to the fact that a
number of roots can share a common subgraph, and that part will be reported in
the size of all the roots that reference the subgraph.
\\

COMMAND: pe.
COMMAND: printexception.
PrintException [-nested] [-lines] [-ccw] [<Exception object address>] [<CCW pointer>]
Expand Down
6 changes: 0 additions & 6 deletions src/SOS/Strike/strike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11985,10 +11985,8 @@ DECLARE_API(StopOnException)
\**********************************************************************/
DECLARE_API(ObjSize)
{
#ifndef FEATURE_PAL
INIT_API();
MINIDUMP_NOT_SUPPORTED();
ONLY_SUPPORTED_ON_WINDOWS_TARGET();

BOOL dml = FALSE;
StringHolder str_Object;
Expand Down Expand Up @@ -12031,10 +12029,6 @@ DECLARE_API(ObjSize)
ExtOut("sizeof(%p) = %d (0x%x) bytes (%S)\n", SOS_PTR(obj), size, size, methodTable.GetName());
}
return Status;
#else
return E_NOTIMPL;
#endif

}

#ifndef FEATURE_PAL
Expand Down
1 change: 1 addition & 0 deletions src/SOS/lldbplugin/soscommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ sosCommandInitialize(lldb::SBDebugger debugger)
g_services->AddCommand("histobj", new sosCommand("HistObj"), "Examines all stress log relocation records and displays the chain of garbage collection relocations that may have led to the address passed in as an argument.");
g_services->AddCommand("histobjfind", new sosCommand("HistObjFind"), "Displays all the log entries that reference an object at the specified address.");
g_services->AddCommand("histroot", new sosCommand("HistRoot"), "Displays information related to both promotions and relocations of the specified root.");
g_services->AddCommand("objsize", new sosCommand("ObjSize"), "Displays the size of the specified object.");
g_services->AddCommand("setclrpath", new sosCommand("SetClrPath"), "Set the path to load the runtime DAC/DBI files.");
g_services->AddCommand("setsymbolserver", new sosCommand("SetSymbolServer"), "Enables the symbol server support ");
g_services->AddCommand("sympath", new sosCommand("SetSymbolServer", "-sympath"), "Add server, cache and directory paths in the Windows symbol path format.");
Expand Down