| 148 | } |
| 149 | |
| 150 | QString LldbCommand::cmdToSend() |
| 151 | { |
| 152 | switch (type()) { |
| 153 | // -gdb-set is only partially implemented |
| 154 | case GdbSet: { |
| 155 | QString env_name = QStringLiteral("environment "); |
| 156 | QString disassembly_flavor = QStringLiteral("disassembly-flavor "); |
| 157 | if (command_.startsWith(env_name)) { |
| 158 | command_.remove(0, env_name.length()); |
| 159 | overrideCmd = QStringLiteral("settings set target.env-vars"); |
| 160 | } else if (command_.startsWith(disassembly_flavor)) { |
| 161 | command_.remove(0, disassembly_flavor.length()); |
| 162 | overrideCmd = QStringLiteral("settings set target.x86-disassembly-flavor"); |
| 163 | } |
| 164 | break; |
| 165 | } |
| 166 | // find the position to insert '-f' |
| 167 | case BreakInsert: { |
| 168 | if (!overrideCmd.isEmpty()) { |
| 169 | // already done |
| 170 | break; |
| 171 | } |
| 172 | int p = command_.length() - 1; |
| 173 | bool quoted = false; |
| 174 | if (command_.at(p) == QLatin1Char('"')) { |
| 175 | quoted = true; // should always be the case |
| 176 | } |
| 177 | --p; |
| 178 | for (; p >= 0; --p) { |
| 179 | // find next '"' or ' ' |
| 180 | if (quoted) { |
| 181 | if (command_.at(p) == QLatin1Char('"') && (p == 0 || command_.at(p - 1) != QLatin1Char('\\'))) |
| 182 | break; |
| 183 | } else { |
| 184 | if (command_.at(p) == QLatin1Char(' ')) |
| 185 | break; |
| 186 | } |
| 187 | } |
| 188 | if (p < 0) p = 0; // this means the command is malformated, we proceed anyway. |
| 189 | |
| 190 | // move other switches like '-d' '-c' into miCommand part |
| 191 | const QStringView commandView = command_; |
| 192 | overrideCmd = miCommand() + QLatin1Char(' ') + commandView.first(p); |
| 193 | command_ = QLatin1String("-f ") + commandView.sliced(p); |
| 194 | break; |
| 195 | } |
| 196 | case BreakWatch: |
| 197 | if (command_.startsWith(QLatin1String("-r "))) { |
| 198 | command_ = QLatin1String("-w read ") + QStringView{command_}.sliced(3); |
| 199 | } else if (command_.startsWith(QLatin1String("-a "))) { |
| 200 | command_ = QLatin1String("-w read_write ") + QStringView{command_}.sliced(3); |
| 201 | } |
| 202 | break; |
| 203 | case StackListArguments: |
| 204 | // some times when adding the command, the current frame is invalid, |
| 205 | // but is valid at sending time |
| 206 | if (command_.endsWith(QLatin1String("-1 -1"))) { |
| 207 | command_.replace(QLatin1String("-1 -1"), QStringLiteral("%1 %1").arg(frame())); |