Set conditional breakpoint in lldb - conditional-statements

ALL,
I need to set a breakpoint in lldb on OSX so that the program will be stopped the second time it hits.
So what should I add to the following:
break set -f myfile.mm -l 100
Trying to debug keyboard issue.
TIA!

Use the -i / --ignore-count flag. In your example, your command would be:
break set -f myfile.mm -l 100 -i 1
This would skip the breakpoint 1 time, and stop the second time (and every time after).
For what it's worth, the docs (from help breakpoint set) say:
-i <count> ( --ignore-count <count> )
Set the number of times this breakpoint is skipped before stopping.

Related

Prevent psql from printing execution time at bottom of output

Here's the output of psql -q -t -c "SELECT 1;"
1
Time: 0.379 ms
It should be possible, but I can't find a way to prevent the execution time from being printed at the bottom - is there a way to prevent it? (Note: I'm already specifying the quiet mode and tuples only flags, to no avail)
Adding -A ignores the .psqlrc file and does the trick

reattaching to screen daemon makes backspace kill whole line

As part of my startup script to set up my desktop, I initialize a screen with several windows. I do this by starting a daemon and sending it -X screen and -X stuff commands, finally reattaching with -r.
Unfortunately, the "create daemon and reattach" method makes all the windows I created turn backspace into a "kill whole line" action. If I create new windows within screen with C-c c, the new windows do not have this behavior. Is this a screen bug, or can I do something special to fix this behavior? I'm using xfce4 and ubuntu 12.10 if that matters
Repro with the following:
screen -S -dm
screen -r
Type several characters and press backspace.
I'm not sure if I'm having the exact same problem as you, as your repro steps didn't work for me, but I did have the same bad behavior in screen (backspace killing the whole line), and managed to fix it.
For me, somehow I repeatedly get into a state where the output of stty is this:
$ stty
speed 9600 baud;
lflags: echoe echok echoke echoctl
iflags: -ixany -imaxbel ignpar
oflags: tab3
cflags: cs8 -parenb -hupcl clocal
eol eol2 erase2 kill min
^# ^# ^# ^H 0
Two things to note here:
There is no erase, only erase2
kill is mapped to ^H
#2 explains my issue, though #1 needs fixing, too.
Normally, ^U is "kill line", but here it is ^H instead.
If I type Ctrl-V, <backspace>, my terminal outputs ^H. So due to that mapping above, that causes the kill (kill line) to happen.
This fixed it for me:
$ stty kill ^U
# now, backspace outputs a literal ^H to the screen, so...
$ stty erase ^H
Note that in order to input the ^H and ^U, you have to use the literal control characters. I do this on my terminal with Ctrl-V, <backspace> and Ctrl-V, Ctrl-U, respectively.
I hope it helps!
I have found a work-around to this issue.
screen -r {session_name} -p 0 -X stuff "stty $(stty -g)"
screen -r {session_name} -p 0 -X stuff $'\n'
screen -r {session_name} -p 0 -X width $COLUMNS $LINES
screen -r {session_name} -p 0 -X stuff $'clear\n'
This takes the current tty settings and "stuffs" them into the screen session on Window 0, the default window that screen create on first launch. Then it "stuff" a newline to simulate pressing enter.
The next two lines are just to tell screen that initial columns and lines should match the calling terminal's columns and lines, then it clears the session's screen so that when you attach to the screen session your prompt will be at the top left. I was having issues of when attaching to the screen session the prompt would be in the middle of the terminal. A minor annoyance, but I wanted it gone.
NOTE: If you call the last two lines from within a script, those environment variables are not set. You will need to replace with $(tput cols) and $(tput lines)

Expect script does not work under crontab

I have an expect script which I need to run every 3 mins on my management node to collect tx/rx values for each port attached to DCX Brocade SAN Switch using the command #portperfshow#
Each time I try to use crontab to execute the script every 3 mins, the script does not work!
My expect script starts with #!/usr/bin/expect -f and I am calling the script using the following syntax under cron:
3 * * * * /usr/bin/expect -f /root/portsperfDCX1/collect-all.exp sanswitchhostname
However, when I execute the script (not under cron) it works as expected:
root# ./collect-all.exp sanswitchhostname
works just fine.
Please Please can someone help! Thanks.
The script collect-all.exp is:
#!/usr/bin/expect -f
#Time and Date
set day [timestamp -format %d%m%y]
set time [timestamp -format %H%M]
#logging
set LogDir1 "/FPerf/PortsLogs"
et timeout 5
set ipaddr [lrange $argv 0 0]
set passw "XXXXXXX"
if { $ipaddr == "" } {
puts "Usage: <script.exp> <ip address>\n"
exit 1
}
spawn ssh admin#$ipaddr
expect -re "password"
send "$passw\r"
expect -re "admin"
log_file "$LogDir1/$day-portsperfshow-$time"
send "portperfshow -tx -rx -t 10\r"
expect timeout "\n"
send \003
log_file
send -- "exit\r"
close
I had the same issue, except that my script was ending with
interact
Finally I got it working by replacing it with these two lines:
expect eof
exit
Changing interact to expect eof worked for me!
Needed to remove the exit part, because I had more statements in the bash script after the expect line (calling expect inside a bash script).
There are two key differences between a program that is run normally from a shell and a program that is run from cron:
Cron does not populate (many) environment variables. Notably absent are TERM, SHELL and HOME, but that's just a small proportion of the long list that will be not defined.
Cron does not set up a current terminal, so /dev/tty doesn't resolve to anything. (Note, programs spawned by Expect will have a current terminal.)
With high probability, any difficulties will come from these, especially the first. To fix, you need to save all your environment variables in an interactive session and use these in your expect script to repopulate the environment. The easiest way is to use this little expect script:
unset -nocomplain ::env(SSH_AUTH_SOCK) ;# This one is session-bound anyway
puts [list array set ::env [array get ::env]]
That will write out a single very long line which you want to put near the top of your script (or at least before the first spawn). Then see if that works.
Jobs run by cron are not considered login shells, and thus don't source your .bashrc, .bash_profile, etc.
If you want that behavior, you need to add it explicitly to the crontab entry like so:
$ crontab -l
0 13 * * * bash -c '. .bash_profile; etc ...'
$

alternative to tail -F

I am monitoring a log file by doing "TAIL -n -0 -F filename". But this is taking up a lof of CPU as there are many messages being written to the logfile. Is there a way, I can open a file and read new/few entries and close it and repeat it every 5 second interval? So that I don't need to keep following the file? How can I remember the last read line to start from the next one in the next run? I am trying to do this in nawk by spawning tail shell cmd.
You won't be able to magically use less resources to tail a file by writing your own implementation. If tail -f is using resources because the file is growing fast, a custom version won't help any if you still want to view all lines as they are being written. You are simply limited by your hardware I/O and/or CPU.
Try using --sleep-interval=S where "S" is a number of seconds (the default is 1.0 - you can specify decimals).
tail -n 0 --sleep-interval=.5 -F filename
If you have so many log entries that tail is bogging down the CPU, how are you able to monitor them?

OS X time until (system/display/disk) sleep?

Does anyone know of a way to query OS X in order to find out how much time is actually left before it enters either system sleep or activates the display sleep (or even disk sleep), either via the command line, or any other method (Ruby or Objective-C for instance)?
I thought something like pmset via the command line might have offered this information, but it appears to only show and update what the current settings are, rather than allow feedback of where in the cycle the OS currently is.
My requirement is that I currently have a Ruby script that I'd like to run only when I'm not using the machine and a simple 'whatcher script' would allow this, but what to 'watch' is the thing I need a little help with.
It seems like there should be a simple answer, but so far I've not found anything obvious. Any ideas?
Heres a bash script to show the commands, which are a little complicated. The idea is that the user sets the system sleep time in the energy saver preference pane. The system will actually go to sleep when no device attached to the computer has moved for that time. So to get the time until the system goes to sleep we need the difference between those 2 results.
#!/bin/bash
# this will check how long before the system sleeps
# it gets the system sleep setting
# it gets the devices idle time
# it returns the difference between the two
#
# Note: if systemSleepTimeMinutes is 0 then the system is set to not go to sleep at all
#
systemSleepTimeMinutes=`pmset -g | grep "^[ ]*sleep" | awk '{ print $2 }'`
if [ $systemSleepTimeMinutes -gt "0" ]; then
systemSleepTime=`echo "$systemSleepTimeMinutes * 60" | bc`
devicesIdleTime=`ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'`
secondsBeforeSleep=`echo "$systemSleepTime - $devicesIdleTime" | bc`
echo "Time before sleep (sec): $secondsBeforeSleep"
exit 0
else
echo "The system is set to not sleep."
exit 0
fi