windbg: how to find size occupied for loaded modules - windbg

In windbg, I can list loaded modules with lm.
How can I find the memory footprint of those assemblies?
I'm analyzing a dump of a process suspected of using too much memory, and one thing I'm noticing is the number of assemblies, but not sure what's the size they occupy in memory.
Also, they don't seem to be in contiguous memory positions. Or are they if I sort lm's output some way?
Thanks!

The !address -summary gives you a good overview.
Check the Image row
0:008> !address -summary
--- Usage Summary ---------------- RgnCount ----------- Total Size -------- %ofBusy %ofTotal
Free 212 b13cb000 ( 2.769 Gb) 69.23%
Heap 455 25281000 ( 594.504 Mb) 47.18% 14.51%
<unknown> 861 2168d000 ( 534.551 Mb) 42.42% 13.05%
Image 662 4e8e000 ( 78.555 Mb) 6.23% 1.92%
Stack 156 3400000 ( 52.000 Mb) 4.13% 1.27%
Other 39 54000 ( 336.000 kb) 0.03% 0.01%
TEB 52 34000 ( 208.000 kb) 0.02% 0.00%
PEB 1 1000 ( 4.000 kb) 0.00% 0.00%

You can check each module's size by using lmvm module_name. There is an ImageSize output indicating the hexidecimal size of that module.
Edited: Another way is to first lm to show all modules, and then use !lmi start_address or !lmi module_name to get information about a specific module. !lmi has a Size field that indicates image size.
Note that for .NET 4 native images loaded, you have to use !lmi start_address, as module name resolution fails.

Related

What are the Fragments in ext2 for?

Recently I was learning ext2
and I found that in the filesystem generated by mkfs.ext2 command, 'Fragment size' is equal to 'Block size', 'Blocks per group' and 'Fragments per group' are also equal, I know what Blocks do, but what is the use of Fragments?
Block size: 1024
Fragment size: 1024
Reserved GDT blocks: 1
Blocks per group: 8192
Fragments per group: 8192

Pymodbus reading holding and input registers : IllegalAddress

I am trying with the interactive version of pymodbus (pip install pymodbus[repl]) to access a modbus device (UPS).
I had accessed it by using mbpoll tool, so the communication and device are both working.
I guess I am having problems to figure out what are the "right" parameters that match the equivalent mbpoll.
From documentation, I am trying to access the values starting at 30405 (page 864 liebert-intellislot-modbus-rtu-reference-guide-SL-28170_0.pdf) what I understand as holding registers as the function is 30xxx:
pg 864 - Vertiv™ | Liebert® IntelliSlot Modbus/BACnet Reference Guide
Table 3.118 Liebert® GXT5—Input and Holding (continued)
Data Label Input Holding # of Reg Scale Notes/Units
System Input Frequency 30405 — 1 10 Uint16
System Input Power Factor L1 30406 — 1 100 Uint16
System Input Power Factor L2 30407 — 1 100 Uint16
System Input Power Factor L3 30408 — 1 100 Uint16
System Input Max Voltage L1-N 30409 — 1 10 Uint16
System Input Min Voltage L1-N 30410 — 1 10 Uint16
System Input Max Voltage L2-N 30411 — 1 10 Uint16
System Input Min Voltage L2-N 30412 — 1 10 Uint16
System Input Max Voltage L3-N 30413 — 1 10 Uint16
Using the mbpool it returns values as expected:
mbpoll -r 396 -t 3 -c 125 -1 -q 192.168.160.1 | \grep -v "65535 (-1)"
-- Polling slave 1...
[396]: 2162
[402]: 7
[405]: 599
[406]: 53
[409]: 2279
[410]: 2048
[415]: 230
[416]: 27
[417]: 60
[418]: 1
[419]: 0
[420]: 190
[431]: 2163
[434]: 599
[435]: 230
[446]: 2
[447]: 0
[448]: 1
[449]: 0
[450]: 1
[451]: 0
[452]: 14446
...
Then I fired /usr/local/bin/pymodbus.console tcp --host 192.168.160.1 --port 502 and at prompt I've tried several combinations of client.read_holding_registers only to get the "message": "IllegalAddress" for all trials below (and others, varying count, unit, addresses, etc):
client.read_holding_registers address=30396 count=10 unit=1
client.read_holding_registers address=396 count=10 unit=1
client.read_holding_registers address=30396 count=10 unit=0
client.read_holding_registers address=396 count=10 unit=0
The complete return of one of theses client.read is:
> client.read_holding_registers address=396 count=10 unit=0
{
"original_function_code": "3 (0x3)",
"error_function_code": "131 (0x83)",
"exception code": 2,
"message": "IllegalAddress"
}
Since it is returning valid values from mbpoll, I suspect I am doing something wrong with the parameters of client.read_holding_registers, but I can't figure out where is the problem.
Both access are from the same machine, at the same time, running opensuse tumbleweed.
Accessing as root or normal user does not make any difference.
I appreciate any hints to deal with the register address with pymodbus module.
As per the comments the mbpoll command line options can cause some confusion:
-t 3:int16 16-bit input register data type with signed int display
-t 4 16-bit output (holding) register data type (default)
This is confusing because the modbus command to read an input register is 4 and for holding registers its 3 (so the reverse of the mbpoll arguments). This is mentioned in an issue.
So the command you need will be client.read_input_registers address=395 count=10 (as per the comments there is also an issue with register numbering - the "Modbus: When 40001 Really Means 1, or 0 Really Means 1 " section in this article explains this well).

Powershell script to search text file and output multiple lines in order

My source file has multiple serial interfaces. I want to simply output each serial line "Serial0/2/0:0" and then the following drops, aborts, etc. on the next lines in the output file under each Serial interface. So far I have this:
get-childitem show-int.log | select-string -pattern drops | foreach {$_.line}
And simply run it with > todays-date. I am a network engineer so forgive how bad I am at ps. I've tried google and putting the many items in quotes but nothing works to my satisfaction.
Serial0/2/0:0 is up, line protocol is up
Hardware is DSX1
MTU 1500 bytes, BW 1536 Kbit/sec, DLY 20000 usec,
reliability 255/255, txload 33/255, rxload 133/255
Encapsulation PPP, LCP Open, multilink Open
Link is a member of Multilink bundle Multilink1, loopback not set
Keepalive set (10 sec)
Last input 00:00:00, output 00:00:00, output hang never
Last clearing of "show interface" counters 1d18h
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops:
381
Queueing strategy: fifo
Output queue: 0/40 (size/max)
5 minute input rate 805000 bits/sec, 188 packets/sec
5 minute output rate 200000 bits/sec, 153 packets/sec
8320454 packets input, 2999426407 bytes, 0 no buffer
Received 0 broadcasts (0 IP multicasts)
22 runts, 0 giants, 0 throttles
30 input errors, 29 CRC, 0 frame, 1 overrun, 0 ignored, 0 abort
7629921 packets output, 1268811436 bytes, 0 underruns
0 output errors, 0 collisions, 4294967295 interface resets
0 unknown protocol drops
0 output buffer failures, 0 output buffers swapped out
7 carrier transitions
Not precise, but easy:
Get-Content show-int.log | select-string 'Serial0/2/0:0' -Context 0,10

what this value mean in address with ' symbol

I am trying to investigate an access violation issue in code. As you can see some of the value for address contains apostrophe character (like in 7fb`80246000).
0:000> !address -summary
--- Usage Summary ---------------- RgnCount ----------- Total Size -------- %ofBusy %ofTotal
Free 424 7fb`80246000 ( 7.982 Tb) 99.78%
The tick mark (grave accent) is just used to separate the lower 4 bytes from the higher 4 bytes of a 64-bit number.
7fb`80246000
is the same as
0x7fb80246000
It is purely for visual aesthetics (making the value easier to parse by humans).

Perl script shows different behavior inside cron job

I'm executing the following commands in a perl script.
#!/usr/bin/perl
my $MPSTAT="/usr/bin/mpstat";
my $GREP="/bin/grep";
my $FREE = "/usr/bin/free";
my $AWK = "/bin/awk";
my $cpu = `$MPSTAT | $GREP all | $AWK '{print (100 - \$12)}'`;
print "CPU is $cpu";
When I run this perl script manually it's getting executed properly and providing the proper CPU Usage in % (100 - Idle CPU).
But when I execute it as a cronjob it always prints 100 & it appears that $12 of awk is getting the value of 0. Any pointers on why it's behaving differently in cron would be helpful.
The main differences between running as a child of cron are:
The user ID might be different (root vs normal user)
The environment is nearly empty, at least pretty different
The second part often means that programs might output in a different language or number format due to the values of the LANG and LC_* environment variables which might be set for the normal user but not when run under cron (or vice versa).
Found the solution using the hint provided by #WinnieNicklaus
mpstat is giving different results in cron.
Normal Execution:
04:53:18 PM all 49.51 0.00 4.79 2.67 0.02 0.34 0.00 0.00 42.68
Inside Cron:
16:54:01 all 49.51 0.00 4.79 2.67 0.02 0.34 0.00 0.00 42.68
Since PM is not getting printed inside cron, when changed the argument for awk as $11 instead of $12 it started working.